Advertisement
Guest User

KSP orbit script

a guest
Sep 18th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. PARAMETER Targetheight. // Prograde burn only!
  2. SET SMA TO (APOAPSIS + 600000 + PERIAPSIS + 600000)/2.
  3. SET SMAF TO (Targetheight + 600000 + APOAPSIS + 600000)/2. // APOAPSIS MAY HAS TO BE CHANGED TO PERIAPSIS!!!!!!
  4. SET Transfer1 TO SQRT(3531600000000*((2/(APOAPSIS + 600000))-(1/SMA))).
  5. SET Transfer2 TO SQRT(3531600000000*((2/(APOAPSIS + 600000))-(1/SMAF))).
  6. print transfer1.
  7. print transfer2.
  8. SET APKM TO ROUND(APOAPSIS/1000).
  9. SET TARKM TO ROUND(Targetheight/1000).
  10. SET PEKM TO ROUND(PERIAPSIS/1000).
  11. SET DeltaVneeded TO Transfer2-Transfer1.
  12. Print (DeltaVneeded) + " DeltaV needed to go into " + TARKM + "Km by " + APKM + "Km orbit".
  13. HUDTEXT(ROUND(DeltaVneeded) + " DeltaV needed to go into " + TARKM + "Km by " + APKM + "Km orbit, ", 15, 2, 50, WHITE, false).
  14.  
  15.  
  16. //node creation
  17.  
  18. SET n to NODE(TIME:SECONDS + ETA:APOAPSIS, 0, 0, DeltaVneeded).
  19. ADD n.
  20.  
  21. SET n TO NEXTNODE.
  22. LOCK STEERING TO n:BURNVECTOR.
  23.  
  24. //calculations of burn time
  25.  
  26. SET a0 TO maxthrust / mass.
  27.  
  28. SET eIsp TO 0.
  29. LIST engines IN my_engines.
  30. FOR eng IN my_engines {
  31. SET eIsp TO eIsp + eng:maxthrust / maxthrust * eng:isp.
  32. }
  33.  
  34. SET Ve TO eIsp * 9.80665.
  35.  
  36. SET final_mass TO mass*CONSTANT():e^(-1*n:BURNVECTOR:MAG/Ve).
  37.  
  38. SET a1 TO maxthrust / final_mass.
  39.  
  40. SET t TO n:BURNVECTOR:MAG / ((a0 + a1) / 2).
  41.  
  42. SET start_time TO TIME:SECONDS + n:ETA - t/2.
  43. SET end_time TO TIME:SECONDS + n:ETA + t/2 - 1.
  44.  
  45. WAIT UNTIL TIME:SECONDS >= start_time.
  46. LOCK throttle TO 1.
  47. WAIT UNTIL TIME:SECONDS >= end_time.
  48. LOCK throttle TO 0.
  49.  
  50. // experimental precision
  51.  
  52. LOCK STEERING TO PROGRADE.
  53.  
  54. if TargetHeight >= apoapsis {
  55. set throt to 0. // variable to hold current throttle value
  56. set scalefactor to 1.2. // scalefactor is some value based on the power of your engine
  57. lock throttle to thrott. // lock the throttle to follow the value of the variable
  58. until apoapsis >= TargetHeight {
  59. set thrott to min(((TargetHeight - apoapsis)/Targetheight) * scalefactor, 0.01). // use min to prevent it going completely to zero
  60. wait 0.01. // wait one tick before recalculating
  61. }
  62. lock throttle to 0. // kill throttle
  63. REMOVE n.
  64. HUDTEXT("Burn complete, current orbit: " + APKM + "Km by " + PEKM + "Km", 10, 2, 50, WHITE, false).
  65. unlock steering.
  66. unlock throttle.
  67.  
  68.  
  69. }
  70.  
  71. WAIT 10.
  72. HUDTEXT ("We are go", 15, 2, 50, WHITE, false).
  73.  
  74.  
  75. //
  76.  
  77. //
  78.  
  79. //
  80.  
  81. // LOOP, CRUCIAL
  82.  
  83. //
  84.  
  85. //
  86.  
  87. //
  88.  
  89. SET SMA2 TO (APOAPSIS + 600000 + PERIAPSIS + 600000)/2.
  90. SET SMAF2 TO (Targetheight + 600000 + APOAPSIS + 600000 + 1000)/2.
  91. SET Transfer3 TO SQRT(3531600000000*((2/(APOAPSIS + 600000))-(1/SMA2))).
  92. SET Transfer4 TO SQRT(3531600000000*((2/(APOAPSIS + 600000))-(1/SMAF2))).
  93. print transfer3.
  94. print transfer4.
  95. SET APKM2 TO ROUND(APOAPSIS/1000).
  96. SET TARKM2 TO ROUND(Targetheight/1000).
  97. SET PEKM2 TO ROUND(PERIAPSIS/1000).
  98. SET DeltaVneeded2 TO Transfer4 - Transfer3.
  99. Print (DeltaVneeded2) + " DeltaV needed to go into " + TARKM2 + "Km by " + APKM2 + "Km orbit".
  100. HUDTEXT(ROUND(DeltaVneeded2) + " DeltaV needed to go into " + TARKM2 + "Km by " + APKM2 + "Km orbit", 15, 2, 50, WHITE, false).
  101.  
  102.  
  103. //node creation
  104.  
  105. SET m to NODE(TIME:SECONDS + ETA:APOAPSIS, 0, 0, DeltaVneeded2).
  106. ADD m.
  107.  
  108. SET m TO NEXTNODE.
  109. LOCK STEERING TO m:BURNVECTOR.
  110.  
  111. //calculations of burn time
  112.  
  113. SET a2 TO maxthrust / mass.
  114.  
  115. SET eIsp2 TO 0.
  116. LIST engines IN my_engines.
  117. FOR eng IN my_engines {
  118. SET eIsp2 TO eIsp2 + eng:maxthrust / maxthrust * eng:isp.
  119. }
  120.  
  121. SET Ve2 TO eIsp2 * 9.80665.
  122.  
  123. SET final_mass2 TO mass*CONSTANT():e^(-1*m:BURNVECTOR:MAG/Ve2).
  124.  
  125. SET a3 TO maxthrust / final_mass2.
  126.  
  127. SET t2 TO m:BURNVECTOR:MAG / ((a2 + a3) / 2).
  128.  
  129. SET start_time2 TO TIME:SECONDS + m:ETA - t2/1.75.
  130. SET end_time2 TO TIME:SECONDS + m:ETA + t2/2 - 1.
  131.  
  132. WAIT UNTIL TIME:SECONDS >= start_time2.
  133. LOCK throttle TO 1.
  134. WAIT UNTIL TIME:SECONDS >= end_time2.
  135. LOCK throttle TO 0.
  136.  
  137. if TargetHeight >= periapsis {
  138. set throt to 0. // variable to hold current throttle value
  139. set scalefactor to 1.2. // scalefactor is some value based on the power of your engine
  140. lock throttle to thrott. // lock the throttle to follow the value of the variable
  141. until periapsis + 200 >= TargetHeight {
  142. set thrott to min(((TargetHeight - periapsis)/Targetheight) * scalefactor, 0.01). // use min to prevent it going completely to zero
  143. wait 0.01. // wait one tick before recalculating
  144. }
  145. }
  146.  
  147. lock throttle to 0. // kill throttle
  148.  
  149. remove m.
  150. unlock steering.
  151. unlock throttle.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement