HvrdlS

Apollo Kerbin Burn

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