spoondawg

Untitled

Sep 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. // Created by: Devon Connor // On: 4/6/2015
  2.  
  3. // Edit By Jake Henry
  4.  
  5. // This file will launch a rocket to the desired altitude
  6.  
  7. // please turn down thrust before beginning script so that when // it is finished the engines remain shutdown
  8.  
  9. // to run the file type "run launch(OrbitHeight)." // where OrbitHeight is the final circular height in km.
  10.  
  11. // mode 1 launches the rocket from the pad // mode 2 takes the rocket to 9km // mode 3 begins the gravity turn until apoapsis is the target height // mode 4 coasts until rocket is within 60s of apoapsis // mode 5 circularizes the orbit // mode 6 deploys solar panels and reliquishes control to the user
  12.  
  13. // /////////// SETUP ////////////
  14. DECLARE PARAMETER orb.
  15. GLOBAL Dv_ToCircle to 0.
  16. set orb to orb*1000.
  17. SAS off.
  18. RCS off. lights off.
  19. lock throttle to 0.
  20. gear off.
  21. clearscreen.
  22. lock TTW to (maxthrust+0.1)/mass.
  23. // ///////////////////////////////////
  24.  
  25. set mode to 2.
  26. if ALT:RADAR < 50 { set mode to 1. }
  27. if periapsis > 70000 { set mode to 4. }
  28.  
  29. until mode = 0 { if mode = 1 {
  30. // launch
  31.  
  32. print "T-MINUS 10 seconds". lock steering to up. wait 1.
  33.  
  34. print "T-MINUS 9 seconds".
  35. lock throttle to 1.
  36. wait 1.
  37.  
  38. print "T-MINUS 8 seconds".
  39. wait 1.
  40.  
  41. print "T-MINUS 7 seco...".
  42. stage.
  43. wait 1.
  44.  
  45. print "Launching...".
  46. wait 2.
  47.  
  48. clearscreen.
  49. set mode to 2.
  50. }
  51.  
  52. else if mode = 2 { // fly up to 9km
  53. lock steering to up.
  54. if (ship:altitude > 9000){
  55. set mode to 3.
  56. }
  57. }
  58. else if mode = 3{ // gravity turn
  59. set targetPitch to max( 8, 90 * (1 - ALT:RADAR / 70000)).
  60. lock steering to heading (90, targetPitch).
  61.  
  62. if SHIP:APOAPSIS > orb{
  63. set mode to 4.
  64. }
  65. if TTW > 20{
  66. lock throttle to 20*mass/(maxthrust+0.1).
  67. }
  68. }
  69. else if mode = 4{ // coast to orbit
  70. lock throttle to 0.
  71. if (SHIP:ALTITUDE < 50000) or (ETA:APOAPSIS > 200) and (VERTICALSPEED > 0) {
  72. if WARP = 0 {
  73. wait 1.
  74. SET WARP TO 3.
  75. }
  76. }
  77. else if (SHIP:ALTITUDE > 50000) or (ETA:APOAPSIS < 140) and (VERTICALSPEED > 0) {
  78. SET WARP to 0.
  79. lock steering to heading(90,0).
  80. wait 2.
  81. set mode to 5.
  82. }
  83.  
  84. if (periapsis > 70000) and mode = 4{
  85. if WARP = 0 {
  86. wait 1.
  87. SET WARP TO 3.
  88. }
  89. }
  90.  
  91. SET IntOrbit to OBT.
  92.  
  93. SET Dv_ToCircle to sqrt(body:mu * (1/(IntOrbit:APOAPSIS + BODY:RADIUS))) - sqrt(body:mu * ((2/(IntOrbit:APOAPSIS + BODY:RADIUS)) - (1/IntOrbit:SEMIMAJORAXIS))). //Delta V to circularize.
  94. SET NODE_1 to NODE(TIME:SECONDS + ETA:APOAPSIS, 0, 0, Dv_ToCircle).
  95. ADD NODE_1.
  96. lock steering to heading(90,0).
  97. //SAS ON.
  98. WAIT 1.
  99. //Set MechJebModuleSmartASS to "MANEUVER".
  100. set CirNODE to NEXTNODE.
  101. set BurnTime to (CirNODE:deltav:mag * ship:mass)/ship:maxthrust. //Estamating burn time for circlizeing.
  102. wait until vang(CirNODE:deltav:normalized, facing:vector:normalized) < 5. //Making sure the ship is pointing in the correct direction.
  103. wait until CirNODE:eta <= (BurnTime/2).
  104. set ThrottleControl to 1.
  105. LOCK Throttle to ThrottleControl.
  106. set CirNODE_INT_DV to CirNODE:deltav.
  107. set ThrottleControl to min((CirNODE:deltav:mag * ship:mass)/ship:maxthrust,1).
  108.  
  109. if vdot(CirNODE_INT_DV, CirNODE:deltav) < 0
  110. {
  111. LOCK Throttle to 0.
  112.  
  113. }
  114.  
  115. if CirNODE:deltav:mag < 0.1
  116. {
  117. wait until vdot(CirNODE_INT_DV, CirNODE:deltav) < 0.5.
  118. LOCK Throttle to 0.
  119. REMOVE NODE_1.
  120.  
  121. }
  122.  
  123. }
  124.  
  125. else if mode = 5 {
  126. if ship:periapsis > orb {
  127. lock throttle to 0.
  128. set mode to 6.
  129. unlock steering.
  130. }
  131. }
  132.  
  133. else if mode = 6 {
  134. lock throttle to 0.
  135. panels on. //Deploy solar panels
  136. lights on.
  137. unlock steering.
  138. //set mode to 0.
  139.  
  140. wait 1.
  141. print "Orbit Stable".
  142. wait 2.
  143. }
  144.  
  145. // this is the staging code to work with all rockets //
  146.  
  147. if stage:number > 0 {
  148. if maxthrust = 0 {
  149. stage.
  150. }
  151. SET numOut to 0.
  152. LIST ENGINES IN engines.
  153. FOR eng IN engines
  154. {
  155. IF eng:FLAMEOUT
  156. {
  157. SET numOut TO numOut + 1.
  158. }
  159. }
  160. if numOut > 0 { stage. }.
  161. }
  162.  
  163. // HERE is the code for the control pannel //
  164.  
  165. clearscreen.
  166. print "LAUNCH PLAN STAGE " + mode.
  167. print " ".
  168. print "Periapsis height: " + round(periapsis, 2) + " m".
  169. print " Apoapsis height: " + round(apoapsis, 2) + " m".
  170. print " ETA to Apoapsis: " + round(ETA:APOAPSIS) + " s".
  171. print " Orbital speed: " + round(velocity:orbit:MAG, 2)+ " m/s".
  172. print " altitude: " + round(altitude, 2) + " m".
  173. print "thrust to weight: " + round((throttle*maxthrust)/mass).
  174. print " ".
  175. print "Currently on Stage: " + stage:number.
  176. wait 0.2.
  177.  
  178. }
Add Comment
Please, Sign In to add comment