HvrdlS

Apollo 8 Main

Jun 26th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. @clobberbuiltins on.
  2. on ag10 {
  3. abort().
  4. }
  5.  
  6. clearscreen.
  7. settings().
  8. flight().
  9. run apollomuninj.
  10. run apollomuncirc.
  11. run apollokerbburn.
  12. run apolloreturn.
  13.  
  14. function printingonlaunch {
  15. clearscreen.
  16. print "Left " + t + " Seconds".
  17. print "Status: " + status1.
  18. wait 0.1.
  19. }
  20.  
  21. function printing {
  22. clearscreen.
  23. set t to time:seconds - now1.
  24. print "T+: " + t.
  25. print "Status: " + status1.
  26. wait 0.1.
  27. }
  28.  
  29. function settings {
  30. set TargetPe to 97000.
  31. set TargetAp to 97500.
  32. set Azimuth to 90.
  33. set radaroffset to ship:altitude.
  34. lock altit to ship:altitude - radaroffset.
  35. set startsteer to lookDirUp(up:forevector, ship:facing:topvector).
  36. set PitchKickAlt to 250.
  37. set sec to 50.
  38. set min to 28.
  39. set hour to 4.
  40. set clock to "04:28:50".
  41. set status1 to "Waiting for launch window".
  42. print "Running hardware...".
  43. wait 5.
  44. set n to time:seconds + ((hour-time:hour)*60+min-time:minute)*60+(sec-time:second).
  45. lock t to (n - time:seconds)+10.
  46. lock rclock to time:clock.
  47. until rclock >= clock and rclock <= clock {
  48. printingonlaunch().
  49. }
  50. }
  51.  
  52. function flight {
  53. //Liftoff
  54. ag1 on.
  55. print "T-10".
  56. wait 0.
  57. sas off.
  58. wait 1.
  59. print "T-9".
  60. stage.
  61. lock throttle to 0.05.
  62. wait 1.
  63. print "T-8".
  64. set now to time:seconds.
  65. lock ti to time:seconds - now.
  66. lock throttle to min(1, 0.05+ti/6).
  67. print "Ignition!".
  68. print "T-7".
  69. wait 1.
  70. print "T-6".
  71. wait 1.
  72. print "T-5".
  73. wait 1.
  74. print "T-4".
  75. wait 1.
  76. print "T-3".
  77. wait 1.
  78. print "T-2".
  79. print "Full throttle".
  80. wait 1.
  81. print "T-1".
  82. wait 1.
  83. print "T-0".
  84. stage.
  85. set now1 to time:seconds.
  86. lock steering to startsteer.
  87. until ship:verticalspeed > 1 {
  88. printing().
  89. }
  90.  
  91. set status1 to "Liftoff".
  92. until altit > PitchKickAlt - 50 {
  93. printing().
  94. }
  95.  
  96. lock steering to heading(Azimuth, 90).
  97. until altit > PitchKickAlt {
  98. printing().
  99. }
  100.  
  101. set status1 to "Pitching and ascending".
  102. lock gravityturn to 90-((ship:apoapsis/TargetPe)*90).
  103. lock steering to heading(Azimuth, gravityturn).
  104. set oldq to ship:q.
  105. wait 0.1.
  106. set newq to ship:q.
  107. until newq < oldq {
  108. set oldq to ship:q.
  109. wait 0.1.
  110. set newq to ship:q.
  111. printing().
  112. }
  113.  
  114. set status1 to "Max-Q passed".
  115. until stage:deltav:duration < 10 {
  116. printing().
  117. }
  118.  
  119. set status1 to "First Stage Center Engine Cutoff".
  120. ship:partstagged("FCE")[0]:shutdown.
  121. until stage:deltav:duration < 2 {
  122. printing().
  123. }
  124.  
  125. set status1 to "First Stage Engines Cutoff".
  126. set now to time:seconds.
  127. lock ti to time:seconds - now.
  128. set thr to throttle.
  129. lock throttle to max(0.05, thr-ti/2).
  130. rcs on.
  131. wait 2.
  132. stage.
  133. set status1 to "Stage Separation".
  134. set ship:control:fore to 1.
  135. wait 1.
  136. lock throttle to 0.05.
  137. wait 2.
  138. set status1 to "Second Stage Ignition".
  139. set now to time:seconds.
  140. lock ti to time:seconds - now.
  141. lock throttle to min(1, ti/1).
  142. set ship:control:fore to 0.
  143. wait 10.
  144. stage.
  145. wait 5.
  146. stage.
  147. set status1 to "Launch Escape System Jettison".
  148. wait 3.
  149. set status1 to "Ascending algorithm is completing".
  150. set thr to 1.
  151. lock throttle to thr.
  152. set pitch to 35.
  153. lock steering to heading(Azimuth, pitch).
  154. set targeteta1 to 90.
  155. set pid1 to pidloop(0.25,0.02,0.02, 0.05,1).
  156. set pid1:setpoint to targeteta1.
  157. set pid2 to pidloop(0.12,0.05,0.03, -25,45).
  158. set pid2:setpoint to TargetPe*1.06.
  159. until ship:apoapsis > TargetPe*1.05 {
  160. set thr to pid1:update(time:seconds,eta:apoapsis).
  161. set pitch to pid2:update(time:seconds,ship:apoapsis).
  162. printing().
  163. wait 0.01.
  164. }
  165.  
  166. set targeteta2 to 15.
  167. set pid1:setpoint to targeteta2.
  168. until ship:apoapsis >= TargetAp and ship:periapsis >= TargetPe*0.98 {
  169. set thr to pid1:update(time:seconds,eta:apoapsis).
  170. set pitch to pid2:update(time:seconds,ship:apoapsis).
  171. set targeteta2 to (((TargetPe-ship:periapsis)/targeteta1)/targeteta1).
  172. set pid1:setpoint to targeteta2.
  173. set pid2:setpoint to TargetPe*1.06.
  174. printing().
  175. if ship:verticalspeed < 5 {
  176. printing().
  177. set pid1 to pidloop(0.01,0.001,0.001, 0.25,1).
  178. set pid2 to pidloop(2,0.3,0.01, -10,30).
  179. set pid1:setpoint to 5.
  180. set pid2:setpoint to 5.
  181. set pitch to pid2:update(time:seconds, ship:verticalspeed).
  182. set thr to pid1:update(time:seconds,ship:verticalspeed).
  183. when stage:deltav:current < 100 then {
  184. set now to time:seconds.
  185. lock ti to time:seconds - now.
  186. set thr to throttle.
  187. lock throttle to max(0.03, thr-ti/2).
  188. set status1 to "Second Stage Engines Cutoff".
  189. wait 2.
  190. stage.
  191. set status1 to "Stage Separation".
  192. wait 1.
  193. lock throttle to 0.03.
  194. wait 2.
  195. set status1 to "Third Stage Engine Ignition".
  196. set now to time:seconds.
  197. lock ti to time:seconds - now.
  198. lock throttle to min(1, ti/1).
  199. }
  200.  
  201. printing().
  202. }
  203. }
  204.  
  205. lock throttle to 0.
  206. set status1 to "Third Stage Engine Cutoff, orbit reached".
  207. }
  208.  
  209. function abort {
  210. if ship:status = "Prelaunch" {
  211. set now1 to time:seconds.
  212. lock t to time:second - now1.
  213. lock steering to loodirup(up:vector,ship:facing:starvector).
  214. wait 0.2.
  215. }
  216.  
  217. lock steering to srfprograde.
  218. set status1 to "Launch Escape System Activated".
  219. until stage:deltav:current < 1 {
  220. printing().
  221. }
  222.  
  223. stage.
  224.  
  225. set status1 to "Launch Escape System Separation".
  226. until altit < ship:apoapsis {
  227. printing().
  228. }
  229.  
  230. set status1 to "Apoapsis reached, descending back to Kerbin".
  231. return1().
  232. }
  233.  
  234. function return1 {
  235. lock steering to srfretrograde.
  236. until altit < 3750 {
  237. printing().
  238. }
  239.  
  240. stage.
  241. wait 1.
  242. stage.
  243. set status1 to "Heat Shield Separation and Drogue Chutes Deploy".
  244. until altit < 1750 {
  245. printing().
  246. }
  247.  
  248. ag8 on.
  249. stage.
  250. set status1 to "Main Chutes Deploy".
  251. until ship:status = "Landed" or ship:status = "Splashed" or ship:status = "Crashed" {
  252. printing().
  253. }
  254.  
  255. print "Touchdown".
  256. set status to "Touchdown".
  257. }
Advertisement
Add Comment
Please, Sign In to add comment