Advertisement
Guest User

all round mission profile script

a guest
Jul 23rd, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. clearscreen.
  2.  
  3. // 1. sets initial conditions
  4.  
  5. set name to SHIP:name.
  6. set engines to ship:partstagged("engine").
  7.  
  8. // 1.1. sets operational mode conditions to initial conditions.
  9.  
  10. set trajectory to "Pre Launch".
  11. set maneuvre to "null".
  12. set mission_complete to false.
  13.  
  14.  
  15.  
  16. // 1.2. sets functial variables to initial conditions.
  17.  
  18. set thr to 0.
  19.  
  20. set tick to 0.01.
  21.  
  22. set taim to 0.
  23. set prevtaim to 0.
  24. set captabel to false.
  25. set counter to 1.
  26. set STAGE_COUNT to -1.
  27. for i in engines set STAGE_COUNT to STAGE_COUNT + 1.
  28. set display_stage to 1.
  29. set direction to heading(0,0).
  30. set throt to thr.
  31. lock steering to direction.
  32. lock throttle to throt.
  33. lock orbitlength to (max(eta:apoapsis,eta:periapsis) - min(eta:apoapsis,eta:periapsis))*2.
  34. set message1 to " ".
  35. set message2 to " ".
  36. set message3 to " ".
  37.  
  38. // above reserved for future variables.
  39. // 1.2. sets navigation variables to initial conditions.
  40.  
  41. set PITCH to 90.
  42. lock atmo_dir to heading(INCL,PITCH).
  43.  
  44. // above reserved for future variables
  45.  
  46.  
  47. // 1.3. sets mission goals
  48.  
  49. set TARGET_APO to 90000.
  50. set TARGET_PER to 90000.
  51. set INCL to 90.
  52. set TARGET_TRAJ to "Orbital".
  53. set TARGET_BODY to "Kerbin".
  54. set TARGET_SMA to (TARGET_APO + TARGET_PER)/2.
  55. lock SMA to (apoapsis + periapsis)/2.
  56.  
  57. lock mission to ((TARGET_APO*0.02 > abs(TARGET_APO - apoapsis)) and (TARGET_PER*0.02 > abs(TARGET_PER - periapsis)) and (trajectory = TARGET_TRAJ)).
  58. lock secondary_mission to (TARGET_APO*0.05 > abs(TARGET_APO - apoapsis)) and (trajectory = TARGET_TRAJ).
  59.  
  60.  
  61. // 1.3.1 adjusts goals for error
  62.  
  63. //set TARGET_PER to TARGET_PER*0.97.
  64. //set TARGET_APO to TARGET_APO*0.99337748.
  65.  
  66. // 2. Prints display.
  67.  
  68. function clearmessages
  69. {
  70. print " " at (3,30).
  71. print " " at (3,31).
  72. print " " at (3,32).
  73. }.
  74. function printmessages
  75. {
  76. parameter message1.
  77. parameter message2.
  78. parameter message3.
  79. set m1 to message1.
  80. set m2 to message2.
  81. set m3 to message3.
  82. print m1 at (3,30).
  83. print m2 at (3,31).
  84. print m3 at (3,32).
  85. }
  86. until counter = 50
  87.  
  88. {
  89.  
  90. print "=" at (counter,0).
  91.  
  92. print "=" at (counter,34).
  93.  
  94. print "-" at (counter,28).
  95.  
  96. print "-" at (counter,6).
  97.  
  98. set counter to counter + 1.
  99.  
  100. }.
  101. set counter to 1.
  102.  
  103. until counter = 33
  104.  
  105. {
  106.  
  107. print "|" at (0,counter).
  108.  
  109. print "|" at (50,counter).
  110.  
  111. set counter to counter +1.
  112.  
  113. }.
  114.  
  115. set counter to 1.
  116.  
  117. until counter = 28
  118.  
  119. {
  120.  
  121. print "|" at (24,counter).
  122.  
  123. set counter to counter +1.
  124.  
  125. }.
  126.  
  127. print " FLIGHT DATA " at (5,0).
  128.  
  129. print " System messages: " at (5,28).
  130.  
  131. print " TELEMETRY " at (8,3).
  132.  
  133. print " PROJECTIONS " at (32,3).
  134.  
  135. until mission_complete
  136. {
  137.  
  138. // 2 Checks if mission complete - Input mission end parameters in condition below
  139.  
  140. if mission
  141. {
  142. wait 5.
  143. toggle lights.
  144. set incl to incl + 180.
  145. set TARGET_TRAJ to "Decaying orbit".
  146. set TARGET_PER to 45000.
  147. set taim to taim + 5.
  148. if mission
  149. {
  150. //set mission_complete to true.
  151. set thr to 0.
  152. unlock steering.
  153. unlock direction.
  154. clearmessages.
  155. if mission <> secondary_mission
  156. {
  157. set message1 to "Primary mission complete".
  158. set mesasage2 to " ".
  159. set mission_complete to false.
  160. // set mission to secondary_mission.
  161. }.
  162. //if mission = secondary_mission
  163. // {
  164. // set message2 to "Mission accomplished".
  165. // }.
  166. }.
  167. }.
  168.  
  169. // 3 Updates display with flight parameters.
  170.  
  171. print ship:body at (6,8).
  172.  
  173. if altitude < 1000 print " Altitude(km): 0" at (5,11).
  174. if altitude > 1000
  175. print " Altitude(km): " + (altitude - mod(altitude,1000))/1000 at (5,11).
  176.  
  177. print " Speed(m/s): " + (ship:airspeed - mod(ship:airspeed,1) + " ") at (5,14).
  178.  
  179. print " Throttle: " + ((throttle / 0.01) - mod(throttle / 0.01,1)) + "% " at (5,17).
  180.  
  181. print " Mass (t): " + (ship:mass - mod(ship:mass,1)) at (5,20).
  182.  
  183. print " Apoapsis(km):" + ((apoapsis - mod(apoapsis,1000))/1000 + " ") at (25,8).
  184.  
  185. if periapsis < 0 print " Periapsis(km): 0" at (25,11).
  186.  
  187. if periapsis > 0 print " Periapsis(km):" + (periapsis - mod(periapsis,1000))/1000 + " " at (25,11).
  188. print " Trajectory:" + trajectory + " " at (25,14).
  189. clearmessages.
  190. printmessages(message1,message2,message3).
  191.  
  192.  
  193. // 4.1 LAUNCH.
  194.  
  195. if (trajectory = "Pre Launch") and (mission_complete = false)
  196. {
  197.  
  198. set message1 to "Initialising flight parameters".
  199. set direction to heading(incl,90).
  200. set thr to 0.1.
  201.  
  202. // 4.1 sets up flight log.
  203.  
  204. set message2 to "Setting up flight log".
  205. set skipl0g to ship:name.
  206. set skipl0g to skipl0g + ".csv".
  207. switch to archive.
  208. //delete skipl0g.
  209. if captabel = false
  210. {
  211. log "Time,Altitude,Speed (x10),Throttle,Apoapsis,Periapsis" to skipl0g.
  212. set captabel to true.
  213. }.
  214. switch to 1.
  215.  
  216. // 4.2 Launches vehicle.
  217.  
  218. stage.
  219. set message3 to "Booster ignition".
  220. wait 3.
  221. set taim to taim + 3.
  222. }.
  223.  
  224. // 5 Staging controls.
  225.  
  226. if (STAGE_COUNT > -0.5) and (mission = false)
  227. if engines[STAGE_COUNT]:flameout
  228. {
  229. set message2 to ("Stage " + display_stage + " completed: discarding booster").
  230. wait 1.
  231. set taim to taim + 1.
  232. stage.
  233. wait 1.
  234. set taim to taim + 1.
  235. stage.
  236. set message1 to ("Stage " + (display_stage + 1) + " Commencing...").
  237. set display_stage to display_stage + 1.
  238. set STAGE_COUNT to STAGE_COUNT - 1.
  239. }.
  240.  
  241. // 6 Checks flight mode
  242.  
  243. if (ship:airspeed < 1) and (prevtaim < 5) set trajectory to "Pre Launch".
  244. if (ship:airspeed > 1) and (apoapsis < 70000) set trajectory to "Ballistic".
  245. if (apoapsis > 70000) and (apoapsis > 0) and (periapsis < 0) set trajectory to "Sub orbital".
  246. if (apoapsis > 70000) and (apoapsis > 0) and (periapsis < 70000) and (periapsis > 40000) set trajectory to "Decaying orbit".
  247. if (apoapsis > 70000) and (apoapsis > 0) and (periapsis > 70000) set trajectory to "Orbital".
  248. if (apoapsis < 0) set trajectory to "On Escape".
  249.  
  250.  
  251. // 7 Performs maneuvres to reach desired trajectory parameters.
  252.  
  253. if (TARGET_TRAJ = "Ballistic") and (mission = false)
  254. {
  255. set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
  256. if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
  257. if pitch > 90 set pitch to 90.
  258. if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
  259. set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
  260.  
  261. }.
  262.  
  263.  
  264. if (TARGET_TRAJ = "Sub Orbital") and (mission = false)
  265. {
  266. set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
  267. if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
  268. if pitch > 90 set pitch to 90.
  269. if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
  270. set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
  271.  
  272. }.
  273.  
  274. if (TARGET_TRAJ = "Orbital") and (mission = false)
  275. {
  276. set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
  277. if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
  278. if pitch > 90 set pitch to 90.
  279. if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
  280. set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
  281.  
  282. }.
  283.  
  284. // Chutes control
  285.  
  286. if (eta:periapsis < eta:apoapsis) and (trajectory = "Ballistic") and (ship:airspeed < 300) and (alt:radar < 1500) toggle chutes.
  287.  
  288. // 8 Thrust control
  289.  
  290. if mission = false
  291. {
  292. if (apoapsis < TARGET_APO*0.8) set thr to 1.
  293. if (apoapsis > TARGET_APO*0.8) set thr to (TARGET_APO*1.03 - Apoapsis) / (TARGET_APO*0.8).
  294. if (eta:apoapsis/orbitlength < 5/360) and (eta:apoapsis < eta:periapsis) and (trajectory = "Sub orbital") set thr to 1.
  295. if (eta:apoapsis/orbitlength < 5/360) and ((trajectory = "Decaying orbit") or (trajectory = "Orbital")) set thr to (TARGET_PER*1.03 - Periapsis) / (TARGET_PER*0.8).
  296. }.
  297.  
  298.  
  299. // 9 Resets controls and counters.
  300.  
  301. if thr < 0.02 set thr to 0.
  302. set throt to thr.
  303. set direction to heading(incl,pitch).
  304.  
  305.  
  306. wait tick.
  307. set prevtaim to taim.
  308. set taim to taim + tick.
  309. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement