HvrdlS

inclination + circulization in one burn script

Jun 4th, 2023 (edited)
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. wait 0.
  2. clearscreen.
  3. set targetinc to 45. // Your target inclination
  4. lock steering to prograde.
  5. set TA1 to (360-ship:orbit:argumentofperiapsis).
  6. set E1 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(TA1)), (orbit:eccentricity + cos(TA1))).
  7. set E2 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(orbit:trueanomaly)), orbit:eccentricity + cos(orbit:trueanomaly)).
  8. set M1 to E1-(orbit:eccentricity*(sin(E1)*180/constant:pi)).
  9. set M2 to E2-(orbit:eccentricity*(sin(E2)*180/constant:pi)).
  10. set n1 to M1-M2.
  11. set n2 to n1+180.
  12. print n1.
  13. print n2.
  14. if n1 <= 270 and n1 >= 90 {
  15. set n3 to n1.
  16. set inc to orbit:inclination-targetinc.
  17. } else if n2 >= 90 and n2 <= 270 {
  18. set n3 to n2.
  19. set inc to targetinc-orbit:inclination.
  20. }
  21.  
  22. wait 0.5.
  23. set T to (n3/360)*orbit:period.
  24. set maneuvertime to time:seconds + T. // 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 ap. // your target apoapsis.
  28. set rad to positionat(ship,maneuvertime)-body:position.
  29. set dir to angleaxis(inc, rad). // rotating radial vector on your inclination degrees
  30. set smja to (ap + TargetAp) / 2. // your final semimajoraxis
  31. set targetvel to sqrt(body:mu*((2/ap)-(1/smja))). // target speed
  32. set targetvel1 to sqrt(myvel:mag^2+targetvel^2-2*myvel:mag*targetvel*cos(inc)).
  33. set targetvec to dir*myvel. // target vector
  34. set targetvec:mag to targetvel.
  35. set result to targetvec-myvel. // burn vector
  36. print vdot(targetvec,myvel).
  37. set apvel to myvel:mag. // burn point speed
  38. set needvel to targetvel-apvel. // needed speed
  39. print needvel.
  40. list engines in engList.
  41. set thr to engList[0]:maxthrust. // Engine Thrust
  42. set m to ship:mass. // Mass
  43. set e to constant():E. // E constant
  44. set p to engList[0]:isp. // ISP
  45. set g to constant:g0. // Gravitational acceleration constant
  46. set burn_duration to abs(g * m * p * (1 - e^(-targetvel1/(g*p))) / thr). // burn duration
  47. print "Crude Estimated burn duration: " + round(burn_duration) + "s".
  48. print "Needed dv: " + abs(needvel) + " m/s".
  49. lock steering to prograde.
  50. lock t to time:seconds.
  51.  
  52. until maneuvertime-t-burn_duration/2 <= 60 and maneuvertime-t-burn_duration/2 > 0 {
  53. clearscreen.
  54. set TA1 to (360-ship:orbit:argumentofperiapsis).
  55. set E1 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(TA1)), (orbit:eccentricity + cos(TA1))).
  56. set E2 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(orbit:trueanomaly)), orbit:eccentricity + cos(orbit:trueanomaly)).
  57. set M1 to E1-(orbit:eccentricity*(sin(E1)*180/constant:pi)).
  58. set M2 to E2-(orbit:eccentricity*(sin(E2)*180/constant:pi)).
  59. set n1 to M1-M2.
  60. set n2 to n1+180.
  61. if n1 <= 270 and n1 >= 90 {
  62. set n3 to n1.
  63. } else if n2 >= 90 and n2 <= 270 {
  64. set n3 to n2.
  65. }
  66.  
  67. print "Angle till node: " + n3 + " Degrees".
  68. print "To maneuver left: " + (maneuvertime-t-burn_duration/2) + " Seconds".
  69. print "Needed dv: " + abs(needvel) + " m/s".
  70. wait 0.1.
  71. }
  72.  
  73. lock steering to result.
  74. //now we need to wait until the burn vector and ship's facing are aligned
  75. until vang(result, ship:facing:vector) < 0.25 {
  76. clearscreen.
  77. set myvel to ship:velocity:orbit.
  78. set targetvec to dir*myvel.
  79. set result to targetvec-myvel.
  80. print "To maneuver left: " + (maneuvertime-t-burn_duration/2) + " Seconds".
  81. print "Needed dv: " + abs(needvel) + " m/s".
  82. wait 0.1.
  83. }
  84.  
  85. until maneuvertime-t-burn_duration/2 <= 10 {
  86. clearscreen.
  87. set myvel to ship:velocity:orbit.
  88. set targetvec to dir*myvel.
  89. set result to targetvec-myvel.
  90. print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
  91. print "Needed dv: " + abs(needvel) + " m/s".
  92. wait 0.1.
  93. }
  94.  
  95. set ship:control:fore to 1.
  96.  
  97. until maneuvertime-t-burn_duration/2 <= 1 {
  98. clearscreen.
  99. set myvel to ship:velocity:orbit.
  100. set targetvec to dir*myvel.
  101. set result to targetvec-myvel.
  102. print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
  103. print "Needed dv: " + abs(needvel) + " m/s".
  104. wait 0.1.
  105. }
  106.  
  107. set ship:control:fore to 0.
  108.  
  109. until maneuvertime-t-burn_duration/2 <= 0.5 {
  110. clearscreen.
  111. set myvel to ship:velocity:orbit.
  112. set targetvec to dir*myvel.
  113. set result to targetvec-myvel.
  114. print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
  115. wait 0.1.
  116. }
  117.  
  118. set now to time:seconds.
  119. lock t to time:seconds - now.
  120. set myvel1 to ship:velocity:orbit:mag.
  121. set tvel to targetvel.
  122. set thrv to 1.
  123. lock throttle to thrv.
  124. until vang(targetvec, myvel) < 0.5 {
  125. clearscreen.
  126. set myvel to ship:velocity:orbit.
  127. set result to targetvec-myvel.
  128. set myvel1 to ship:velocity:orbit:mag.
  129. print vang(targetvec, myvel).
  130. print "Time left: " + (burn_duration-t) + " Seconds".
  131. print "Speed left: " + (tvel-myvel1) + " m/s".
  132. wait 0.1.
  133. }
  134.  
  135. set targetvec to myvel.
  136. set result to targetvec.
  137. set thr to 0.3.
  138. until myvel1 > tvel {
  139. clearscreen.
  140. set result to targetvec.
  141. set myvel to ship:velocity:orbit.
  142. set myvel1 to ship:velocity:orbit:mag.
  143. print "Time left: " + (burn_duration-t) + " Seconds".
  144. print "Speed left: " + (tvel-myvel1) + " m/s".
  145. wait 0.1.
  146. }
  147.  
  148. lock throttle to max(0, thrv-t/0.3).
  149. lock steering to prograde.
  150. set ship:control:fore to -1.
  151. wait 1.
  152. set ship:control:fore to 0.
  153. wait 5.
  154. unlock steering.
  155. unlock throttle.
Advertisement
Add Comment
Please, Sign In to add comment