Advertisement
Guest User

KOS polar launch

a guest
Sep 4th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. //launch.ks
  2. //code by "Seth Persigehl" used as reference
  3.  
  4. //This program launches the LKOS from the KSC and flies it into low Kerbin orbit
  5.  
  6. clearscreen.
  7.  
  8. //Set the ship to a known configuration
  9. SAS off.
  10. RCS off.
  11. lights off.
  12. lock throttle to 0.
  13. gear off.
  14.  
  15. //Init variables
  16. declare GLOBAL targetApoapsis to 100000.
  17. declare GLOBAL targetPeriapsis to 100000.
  18. declare GLOBAL targetInclination to 90.
  19. declare GLOBAL currentInclination to 0.
  20. declare GLOBAL targetAzimuth to 90.
  21. declare GLOBAL targetPitch to 90.
  22. declare GLOBAL stages to 0.
  23.  
  24. RUN launch_util.ks.
  25.  
  26. LOCAL azimuthData to initAzimuth(targetApoapsis, targetPeriapsis, targetInclination).
  27.  
  28. set runmode to 2. //Safety in case rocket is mid-flight
  29. if ALT:RADAR < 50 //Waiting for takeoff
  30. {
  31. set runmode to 1.
  32. }
  33.  
  34. until runmode = 0 //Run until we end the program
  35. {
  36. lock currentInclination to SHIP:OBT:INCLINATION.
  37. lock targetAzimuth to getAzimuth(azimuthData).
  38. if runmode = 1 //Ship is on the launchpad
  39. {
  40. lights on.
  41. print "Launch sequence start" + " " at (5,1).
  42. print "T - 30 seconds" at (5,2).
  43. wait 10.
  44. SAS on.
  45. lock steering to UP. //Point the rocket straight up
  46. print "Internal guidance online" + " " at (5,1).
  47. print "T - 20 seconds" at (5,2).
  48. wait 10.
  49. print "All systems at go" + " " at (5,1).
  50. print "T - 10 seconds" at (5,2).
  51. wait 1.
  52. print "T - 09 seconds" at (5,2).
  53. wait 1.
  54. stage. //Activate Engines
  55. print "Ignition sequence start" + " " at (5,1).
  56. print "T - 08 seconds" at (5,2).
  57. wait 1.
  58. print "T - 07 seconds" at (5,2).
  59. wait 1.
  60. print "T - 06 seconds" at (5,2).
  61. wait 1.
  62. print "T - 05 seconds" at (5,2).
  63. wait 1.
  64. print "T - 04 seconds" at (5,2).
  65. wait 1.
  66. print "T - 03 seconds" at (5,2).
  67. wait 1.
  68. set TVAL to (1.0). //Throttle up to 100%
  69. lock throttle to TVAL.
  70. print "All engines running" + " " at (5,1).
  71. print "T - 02 seconds" at (5,2).
  72. wait 1.
  73. print "T - 01 seconds" at (5,2).
  74. wait 1.
  75. stage. //Release launch clamps
  76. set stages to (stages + 1).
  77. print "Liftoff!" + " " at (5,1).
  78. print "T - 00 seconds" at (5,2).
  79. set runmode to 2. //Go to the next runmode
  80. }
  81.  
  82. else if runmode = 2 // Fly UP to 10,000m
  83. {
  84. set targetPitch to 90.
  85. lock steering to heading (targetAzimuth + 0,targetPitch). //Straight up.
  86. set TVAL to (1.0).
  87. if SURFACESPEED > 100 //Once altitude is higher than 10km, go to Gravity Turn mode
  88. {
  89. print "Performing Gravity turn" + " " at (5,1).
  90. set runmode to 3.
  91. }
  92. }
  93.  
  94. else if runmode = 3 //Gravity turn
  95. {
  96. if ALT:RADAR < 15000 //Pitch between 90 and 45 degrees
  97. {
  98. set targetPitch to (45 * (2 - (ALT:RADAR / 15000))).
  99. }
  100. else //Pitch between 45 and 5 degrees
  101. {
  102. set targetPitch to (5 + 40 * (1 - (ALT:RADAR-15000) / 45000)).
  103. }
  104.  
  105. lock steering to heading ( targetAzimuth + 0, targetPitch). //Heading 90' (East), then target pitch
  106. set TVAL to (1.0).
  107. if (stages = 1) and (SURFACESPEED > 250)
  108. {
  109. print "throttle down for max Q" + " " at (5,1).
  110. set TVAL to (0.667).
  111. }
  112. else if stages = 2
  113. {
  114. print "throttle up" + " " at (5,1).
  115. }
  116.  
  117. if SHIP:APOAPSIS > targetApoapsis
  118. {
  119. print "main engine cut off" + " " at (5,1).
  120. set runmode to 4.
  121. }
  122. }
  123.  
  124. else if runmode = 4 //Coast to Ap
  125. {
  126. set targetPitch to 3.
  127. lock steering to heading ( targetAzimuth + 0, targetPitch). //Stay pointing 3 degrees above horizon
  128. set TVAL to (0.0). //Engines off.
  129. if (SHIP:ALTITUDE > 70000) and (ETA:APOAPSIS > 60) and (VERTICALSPEED > 0) {
  130. if WARP = 0 // If we are not time warping
  131. {
  132. wait 1. //Wait to make sure the ship is stable
  133. print "deploying solar panels" + " " at (5,1).
  134. panels on. //Deploy solar panels
  135. wait 5.
  136. print "coasting to apoapsis" + " " at (5,1).
  137. SET WARP TO 3. //Be really careful about warping
  138. }
  139. }.
  140. else if ETA:APOAPSIS < 60
  141. {
  142. SET WARP to 0.
  143. set runmode to 5.
  144. }
  145. }
  146.  
  147. else if runmode = 5 //Burn to raise Periapsis
  148. {
  149. set targetPitch to 0.
  150. lock steering to heading ( targetAzimuth + 0, targetPitch).
  151. if ETA:APOAPSIS < 5 or VERTICALSPEED < 0 //If we're less 5 seconds from Ap or loosing altitude
  152. {
  153. print "performing circularization burn" + " " at (5,1).
  154. if (SHIP:PERIAPSIS < targetPeriapsis * 0.8) //full throttle
  155. {
  156. set TVAL to (1.0).
  157. }
  158. else //decrease throttle near circularization
  159. {
  160. set TVAL to (1.0) - min(0.8, ((SHIP:PERIAPSIS - targetPeriapsis * 0.8) / (targetPeriapsis - targetPeriapsis * 0.8))).
  161. }
  162.  
  163. }
  164. if (SHIP:PERIAPSIS > targetPeriapsis) or (SHIP:PERIAPSIS > targetApoapsis * 0.995) //If the periapsis is high enough or getting close to the apoapsis
  165. {
  166. set TVAL to (0.0).
  167. set runmode to 10.
  168. }
  169. }
  170.  
  171. else if runmode = 10 //Final touches
  172. {
  173. set TVAL to (0.0). //Shutdown engine.
  174. lights on.
  175. unlock steering.
  176. print "ascent completed" + " " at (5,1).
  177. set runmode to 0.
  178. }
  179.  
  180. //Housekeeping
  181. // Check for flameout of any of the existing engines:
  182. set stg_numF to 0.
  183. list engines in stg_eList.
  184. for stg_eng in stg_eList
  185. {
  186. if stg_eng:flameout
  187. {
  188. set stg_numF to stg_numF + 1.
  189. }.
  190. }.
  191. if stg_numF > 0 //If any engines flamed out: stage
  192. {
  193. lock throttle to 0.
  194. wait 2.
  195. stage.
  196. set stages to (stages + 1).
  197. wait 2.
  198. lock throttle to TVAL.
  199. }
  200.  
  201. set finalTVAL to TVAL.
  202. lock throttle to finalTVAL. //Write our planned throttle to the physical throttle
  203.  
  204. //Print data to screen.
  205. print "T + " + round(MISSIONTIME) at (5,2).
  206. print "RUNMODE: " + runmode + " " at (5,4).
  207. print "STAGE: " + stages + " " at (5,5).
  208. print "ALTITUDE: " + round(SHIP:ALTITUDE) + " " at (5,6).
  209. print "ETA to AP: " + round(ETA:APOAPSIS) + " " at (5,7).
  210.  
  211. print "APOAPSIS: " + "current: " + round(SHIP:APOAPSIS) + " target: " + round(targetApoapsis) + " " at (5,15).
  212. print "PERIAPSIS: " + "current: " + round(SHIP:PERIAPSIS) + " target: " + round(targetPeriapsis) + " " at (5,16).
  213. print "INCLINATION: " + "current: " + round(currentInclination) + " target: " + round(targetInclination) + " " at (5,17).
  214. print "STEERING: " + "azimuth: " + round(targetAzimuth) + " pitch : " + round(targetPitch) + " " at (5,18).
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement