HvrdlS

Apollo Mun Circulization

Jun 26th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. @clobberbuiltins on.
  2. clearscreen.
  3. main().
  4.  
  5. function main {
  6. lock steering to prograde.
  7. wait 5.
  8. unlock steering.
  9. unlock throttle.
  10. set ship:control:roll to 0.05.
  11. wait 1.
  12. set ship:control:roll to 0.
  13. set status1 to "All controls are unlocked.Awaiting to enter Mun sphere of influence".
  14. set now to time:seconds.
  15. set ti to time:seconds-now.
  16. until ship:body:name = "Mun" {
  17. printing().
  18. set ti to time:seconds-now.
  19. print "Left to enter Mun Sphere of Influence: " + (orbit:nextpatcheta/60) + " Minutes".
  20. wait 0.1.
  21. }
  22.  
  23. set n to time:seconds+eta:periapsis.
  24. lock ti to n-time:seconds.
  25. set status1 to "Entered sphere of influence, awaiting for burn".
  26. wait 1.
  27. set maneuvertime to time:seconds + eta:periapsis. // when the burn should start
  28. set myvel to velocityat(ship,maneuvertime):orbit.
  29. set ap to ship:body:altitudeOf(positionAt(ship,maneuvertime))+body:radius. // altitude on burn point
  30. set TargetAp to ap.. // your target apoapsis.
  31. set smja to (ap + TargetAp) / 2. // your final semimajoraxis
  32. set targetvel to sqrt(body:mu*((2/ap)-(1/smja))). // target speed
  33. set apvel to myvel:mag. // burn point speed
  34. set needvel to abs(targetvel-apvel). // needed speed
  35. list engines in engList.
  36. set thr to engList[0]:maxthrust. // Engine Thrust
  37. set m to ship:mass. // Mass
  38. set e to constant():E. // E constant
  39. set p to engList[0]:isp. // ISP
  40. set g to constant:g0. // Gravitational acceleration constant.
  41. set burn_duration to abs(g * m * p * (1 - e^(-needvel/(g*p))) / thr). // burn duration
  42. print "Crude Estimated burn duration: " + round(burn_duration) + "s".
  43. print "Needed dv: " + abs(needvel) + " m/s".
  44. lock steering to retrograde.
  45. wait 1.
  46.  
  47. until ti-burn_duration/2 <= 60 and ti-burn_duration/2 > 0 {
  48. print "To maneuver left: " + (ti-burn_duration/2) + " Seconds".
  49. print "Needed dv: " + abs(needvel) + " m/s".
  50. wait 0.1.
  51. printing().
  52. }
  53.  
  54. set status1 to "One Minute Till Burn".
  55. lock steering to retrograde.
  56. //now we need to wait until the burn vector and ship's facing are aligned
  57. until vang(-ship:velocity:orbit, ship:facing:vector) < 0.25 {
  58. print "To maneuver left: " + (ti-burn_duration/2) + " Seconds".
  59. print "Needed dv: " + abs(needvel) + " m/s".
  60. wait 0.1.
  61. printing().
  62. }
  63.  
  64. until ti-(burn_duration/2) <= 10 {
  65. print "To maneuver left: " + (ti-(burn_duration/2)) + " Seconds".
  66. print "Needed dv: " + abs(needvel) + " m/s".
  67. wait 0.1.
  68. printing().
  69. }
  70.  
  71. set ship:control:fore to 0.5.
  72. set status1 to "RCS activated for ullage".
  73. until ti-(burn_duration/2) <= 1 {
  74. print "To maneuver left: " + (ti-(burn_duration/2)) + " Seconds".
  75. print "Needed dv: " + abs(needvel) + " m/s".
  76. wait 0.1.
  77. printing().
  78. }
  79.  
  80. set ship:control:fore to 0.
  81. until ti-(burn_duration/2) <= 0.5 {
  82. print "To maneuver left: " + (ti-(burn_duration/2)) + " Seconds".
  83. wait 0.1.
  84. printing().
  85. }
  86.  
  87. set now to time:seconds.
  88. lock ti to time:seconds - now.
  89. set myvel1 to ship:velocity:orbit:mag.
  90. set tvel to targetvel.
  91. lock throttle to 1.
  92. set status1 to "SM Engine Activated".
  93. until ti > burn_duration {
  94. set myvel1 to ship:velocity:orbit:mag.
  95. print "Time left: " + (burn_duration-ti) + " Seconds".
  96. print "Speed left: " + (tvel-myvel1) + " m/s".
  97. wait 0.1.
  98. printing().
  99. }
  100.  
  101. lock throttle to max(0, 1-t/0.3).
  102. set status1 to "Circulization burn has completed.All controls are unlocked".
  103. set ship:control:fore to -1.
  104. wait 1.
  105. set ship:control:fore to 0.
  106. wait 5.
  107. unlock steering.
  108. unlock throttle.
  109. }
  110.  
  111. function printing {
  112. clearscreen.
  113. set t to (time:seconds - now1)/60.
  114. print "T+: " + t + " Minutes".
  115. print "Status: " + status1.
  116. wait 0.1.
  117. }
Advertisement
Add Comment
Please, Sign In to add comment