HvrdlS

apollo mun injection

Jun 26th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. @clobberbuiltins on.
  2. clearscreen.
  3. main().
  4. coastandcor().
  5.  
  6. function main {
  7. set Tar to body("Mun").
  8. set tap to Tar:altitude+body:radius.
  9. lock steering to prograde.
  10. set status1 to "Awaiting for user input to search needed phase angle for burn(AG9)".
  11. until ag9 {
  12. printing().
  13. }
  14.  
  15. toggle ag9.
  16. set status1 to "Awaiting for 90 degrees phase angle".
  17. lock steering to prograde.
  18. until checkang {
  19. printing().
  20. print checkang.
  21. }
  22.  
  23. set status1 to "Phase angle reached, awaiting for burn".
  24. set maneuvertime to time:seconds + ((abs(cur_angle)-90)/360)*orbit:period. // when the burn should start
  25. set myvel to velocityat(ship,maneuvertime):orbit.
  26. set ap to ship:body:altitudeOf(positionAt(ship,maneuvertime))+body:radius. // altitude on burn point
  27. set TargetAp to tap. // your target apoapsis.
  28. set smja to (ap + TargetAp) / 2. // your final semimajoraxis
  29. set targetvel to sqrt(body:mu*((2/ap)-(1/smja))). // target speed
  30. set apvel to myvel:mag. // burn point speed
  31. set needvel to targetvel-apvel. // needed speed
  32. set thr to ship:partstagged("TE")[0]:maxthrust. // Engine Thrust
  33. set m to ship:mass. // Mass
  34. set e to constant():E. // E constant
  35. set p to ship:partstagged("TE")[0]:isp. // ISP
  36. set g to constant:g0. // Gravitational acceleration constant.
  37. set burn_duration to abs(g * m * p * (1 - e^(-needvel/(g*p))) / thr). // burn duration
  38. print "Crude Estimated burn duration: " + round(burn_duration) + "s".
  39. print "Needed dv: " + abs(needvel) + " m/s".
  40. lock steering to prograde.
  41. lock ti to time:seconds.
  42. wait 1.
  43.  
  44. until maneuvertime-ti-burn_duration/2 <= 60 and maneuvertime-ti-burn_duration/2 > 0 {
  45. print "To maneuver left: " + (maneuvertime-ti-burn_duration/2) + " Seconds".
  46. print "Needed dv: " + abs(needvel) + " m/s".
  47. wait 0.1.
  48. printing().
  49. }
  50.  
  51. lock steering to prograde.
  52. //now we need to wait until the burn vector and ship's facing are aligned
  53. until vang(ship:velocity:orbit, ship:facing:vector) < 0.25 {
  54. print "To maneuver left: " + (maneuvertime-ti-burn_duration/2) + " Seconds".
  55. print "Needed dv: " + abs(needvel) + " m/s".
  56. wait 0.1.
  57. printing().
  58. }
  59.  
  60. until maneuvertime-ti-burn_duration/2 <= 10 {
  61. print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
  62. print "Needed dv: " + abs(needvel) + " m/s".
  63. wait 0.1.
  64. printing().
  65. }
  66.  
  67. set ship:control:fore to 0.5.
  68. set status1 to "RCS activated for ullage".
  69. until maneuvertime-ti-burn_duration/2 <= 1 {
  70. print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
  71. print "Needed dv: " + abs(needvel) + " m/s".
  72. wait 0.1.
  73. printing().
  74. }
  75.  
  76. set ship:control:fore to 0.
  77. until maneuvertime-ti-burn_duration/2 <= 0.5 {
  78. print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
  79. wait 0.1.
  80. printing().
  81. }
  82.  
  83. set now to time:seconds.
  84. lock ti to time:seconds - now.
  85. set myvel1 to ship:velocity:orbit:mag.
  86. set tvel to targetvel.
  87. lock throttle to 1.
  88. set status1 to "Third Stage Engine Activated".
  89. until ti > burn_duration or orbit:hasnextpatch = True {
  90. set myvel1 to ship:velocity:orbit:mag.
  91. print "Time left: " + (burn_duration-ti) + " Seconds".
  92. print "Speed left: " + (tvel-myvel1) + " m/s".
  93. wait 0.01.
  94. printing().
  95. }
  96.  
  97. lock throttle to max(0, 1-t/0.3).
  98. lock steering to prograde.
  99. set ship:control:fore to -1.
  100. wait 1.
  101. set ship:control:fore to 0.
  102. wait 5.
  103. unlock steering.
  104. unlock throttle.
  105. stage.
  106. set status1 to "Third Stage Separation".
  107. }
  108.  
  109. function coastandcor {
  110. lock steering to prograde.
  111. ag2 on.
  112. ag3 on.
  113. set status1 to "Antenna opened, fuel cells are working(AG2 to disable them).Waiting for input command for correction burn(AG9)".
  114. until ag9 {
  115. printing().
  116. }
  117.  
  118. toggle ag9.
  119. set ship:control:fore to 0.4.
  120. set status1 to "Correction burn".
  121. set norm to vcrs(velocityAt(ship,orbit:nextpatch:eta:periapsis+time:seconds):orbit, -positionAt(Mun,orbit:nextpatch:eta:periapsis+time:seconds)).
  122. set rad to vcrs(velocityAt(ship,orbit:nextpatch:eta:periapsis+time:seconds):orbit, norm).
  123. set fore to vcrs(rad,norm).
  124. until orbit:nextpatch:periapsis > 55000 and orbit:apoapsis > 12380000 {
  125. printing().
  126. }
  127.  
  128. set ship:control:fore to 0.
  129. set status1 to "Correction completed".
  130. }
  131.  
  132. function checkang {
  133. set VecS to ship:position - body("Kerbin"):position.
  134. set VecT to Tar:position - body("Kerbin"):position.
  135. set VecHV to vxcl(ship:up:vector, ship:velocity:orbit).
  136. set VecST to Tar:position - ship:position.
  137. set cur_angle to vang(VecT, VecS).
  138. set targetang to 89.5.
  139. if vang(Vect, VecS)>90 {
  140. set cur_angle to -cur_angle.
  141. }
  142.  
  143. print cur_angle.
  144. print targetang.
  145. wait 0.1.
  146. return cur_angle > -targetang - 30 and cur_angle < -targetang and vang(ship:velocity:orbit,Tar:position-ship:position)<50.
  147. }
  148.  
  149.  
  150. function printing {
  151. clearscreen.
  152. set t to (time:seconds-now1)/60.
  153. print "T+: " + t + " Minutes".
  154. print "Status: " + status1.
  155. wait 0.1.
  156. }
Advertisement
Add Comment
Please, Sign In to add comment