Advertisement
niwo

launch_0.3.ks

Aug 20th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.59 KB | None | 0 0
  1. // Basic Launch Script for KSP Rockets with or without Booster.
  2. // by Niwo
  3. // Version 0.3
  4.  
  5. // Declaration
  6. set tVal to 0.      // Throttle Value
  7. set aborted to 0.  
  8. set liftoff to 0.
  9. set f to 0.         // Failure Counter
  10. set s to 0.         // Stage Counter Variable
  11. set targetPeriapsis to 95000.
  12. set targetApoapsis to 100000.
  13. set boosters to 0.
  14. // SET Stage1 TO SHIP:PARTSDUBBED("Stage1")[0]. // TODO
  15.  
  16. // Booster check.
  17. if ship:solidfuel > 0 {
  18.     set boosters to 1. // are there any boosters?
  19.     }.
  20.  
  21.  if ALT:RADAR < 50 {
  22. // Phase 1
  23. // Prestart Checks    
  24. // TODO: Make it smarter with while i++ and  at (x,x). stuff
  25.  
  26.     clearscreen.
  27.     Print "Initiating Prelaunch Configuration".  
  28.     print "#____".
  29.     wait 0.5.
  30.    
  31. // Setting up SAS
  32.     clearscreen.
  33.     Print "Initiating Prelaunch Configuration".
  34.     print "##___".
  35.     PRINT "SETTING UP SAS".
  36.     sas on.
  37.     wait 0.5.
  38.    
  39.     clearscreen.
  40.     Print "Initiating Prelaunch Configuration".
  41.     print "###__".
  42.     PRINT "SETTING UP SAS".
  43.     PRINT "SETTING SAS TO STABILITYASSIST".
  44.     SET SASMODE TO "STABILITYASSIST".
  45.      wait 0.5.
  46.  
  47. // Setting up Throttle
  48.     clearscreen.
  49.     Print "Initiating Prelaunch Configuration".
  50.     print "####_".
  51.     PRINT "SETTING UP SAS".
  52.     PRINT "SETTING SAS TO STABILITYASSIST".
  53.     PRINT "Setting Full Throttle".
  54.     set tVal to 1
  55.     lock throttle to tVal.
  56.     wait 0.5.
  57. // Setting Steering to up 0°
  58.     clearscreen.
  59.     Print "Initiating Prelaunch Configuration".
  60.     print "#####".
  61.     PRINT "SETTING UP SAS".
  62.     PRINT "SETTING SAS TO STABILITYASSIST".
  63.     PRINT "Setting Full Throttle".
  64.     Print "Setting Steering to up".
  65.     lock steering to up + R(0,0,180). wait 1.
  66.  
  67. // Phase 2
  68. // LAUNCH!!!
  69.  
  70. // If you want a Countdown.
  71.  
  72. FROM {local countdown is 5.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
  73.     PRINT "Countdown: " + countdown at (1,7).
  74.     print " ".
  75.     WAIT 1.
  76. }
  77.  
  78. PRINT "Ignition!".
  79. stage.
  80. wait 2.
  81.  until ALT:RADAR < 10 {
  82.  
  83.     if verticalspeed > 10 + aborted = 0 + liftoff = 0 {
  84.     PRINT " ".
  85.     PRINT "LIFTOFF!".
  86.     set liftoff to 1.
  87.     break.
  88.     }.
  89.     else if liftoff = 0 {
  90.     set aborted to 1.
  91.     lock throttle to 0.
  92.     set tVal to 0.
  93.     sas off.
  94.         until f = 5 {
  95.             clearscreen.
  96.             print "FAILURE! Abort Start immediatly !!!".
  97.             wait 0.5.
  98.             clearscreen.
  99.             print " ".
  100.             wait 0.5.
  101.             set f to (f + 1).
  102.         }.
  103.     clearscreen.   
  104.     print "Start aborted.".
  105.     print "Launch Program Terminated.".
  106.     break.
  107.     }.
  108. }.
  109. if liftoff = 1 {
  110.  
  111.  
  112. // Permanent Checking
  113. // Seperating Boosters
  114.  when stage:solidfuel < 0.01  and boosters = 1 then {
  115.     stage.
  116.     print " ".
  117.     print "Boosters separated.".
  118.     }.
  119.  
  120. // Seperating Stage (Seperator and next Stage Engine must be in the same stage section!!!)
  121.     when stage:liquidfuel < 0.1 OR SHIP:MAXTHRUST < 0.1 and tVal > 0.1  and s < 4 then { // Fallback function: if stage:liquidfuel refers to the whole ship, or ship:maxthrust and ... initiates staging.
  122.     // when stage:liquidfuel < 0.1 then {
  123.     stage.  
  124.     set s to MAX(4, s + 1 ).
  125.     print " ".
  126.     print "Stage " + s + " separated.". // add num counter.
  127.     preserve.
  128.     }.
  129.  
  130.  
  131. // Phase 3
  132. // Climb
  133. wait until altitude > 2000.
  134. Print "2000m ASL. Turn HDG 270 Degrees.".
  135. lock steering to up + R(0,0,270).
  136.  
  137. // Phase 4
  138. // Roll Program
  139. wait until altitude > 10000.
  140. Print "10000m ASL. " .
  141. PRINT "Commencing Roll Program".
  142. set roll to 1.  
  143. until altitude  > 31000 {
  144. if roll = 1 {
  145.    set targetPitch to MAX(30, 90 * (1 - ALT:RADAR / 31000)). //Pitch over gradually until levelling out to 30 degrees at 31km
  146.         lock steering to heading ( 90, targetPitch). //Heading 90' (East), then target pitch
  147.         print "Target Pitch: " + round(targetPitch) + " Degrees." at (1,40).
  148.         if targetPitch < 31 {
  149.         // lock steering to heading ( 90, 30). //Heading 90' (East), then target pitch 30°, fallback
  150.             set roll to 0.
  151.             print "Roll complete.".
  152.             print "                                                            " at (1,40).
  153.             }.
  154.     }.
  155.    
  156. }.
  157.  
  158. // Phase 5
  159. // Orbit
  160. wait until altitude > 32000.
  161. print "Waiting for Apoapsis to be 100000 km (ASL).".
  162. wait until ALT:APOAPSIS > targetApoapsis.
  163. set tVal to 0.
  164. PRINT "Switching SAS off, to save energy.".
  165. sas off.
  166. // lock throttle to 0. // pretty obsolete.
  167.     if ETA:APOAPSIS < 59 {
  168.     print "ETA to AP:        " + round(ETA:APOAPSIS) + " s     " at (5,8).
  169.     }.
  170.     else {
  171.     print "ETA to AP:        " + round(ETA:APOAPSIS / 60) + " min  " at (5,8).
  172.     }.
  173. // lock steering to prograde.
  174. print "Waiting for circularization burn.".
  175. wait until eta:apoapsis < 30.
  176. SET WARP TO 0.
  177. wait 5.
  178. PRINT "SETTING SAS TO ON AND PROGRADE".
  179. sas on.
  180. wait 0.5.
  181. SET SASMODE TO "PROGRADE".
  182. wait 4.
  183. set tVal to 0.7.
  184. lock throttle to tVal. // repeated for saftey. Test if its obsolete.
  185.  
  186.   until   ALT:PERIAPSIS > targetPeriapsis {
  187.         if ETA:APOAPSIS < 5 or VERTICALSPEED < 0 { //If we're less 5 seconds from Ap or loosing altitude
  188.             if vBurn = 0 {
  189.                 print "Burn.".
  190.                 set vBurn to 1.
  191.                 }.
  192.             set tVal to 1.
  193.             }
  194.         if (SHIP:PERIAPSIS > targetPeriapsis) or (SHIP:PERIAPSIS > targetApoapsis * 0.95) {
  195.             //If the periapsis is high enough or getting close to the apoapsis
  196.             set tVal to 0.
  197.            
  198.             }
  199.         }
  200.  
  201.  
  202. wait until ALT:PERIAPSIS > targetPeriapsis.
  203. set tVal to 0.
  204. lock throttle to 0.
  205. wait 2.
  206. PRINT "Switching SAS off, to save energy.".
  207. sas off.
  208. wait 1.
  209. until f = 10 {
  210.     clearscreen.
  211.     print "Orbit Reached.".
  212.     print "KILL ENGINES!!!".
  213.     wait 0.5.
  214.     clearscreen.
  215.     print "Orbit Reached.".
  216.     print " ".
  217.     wait 0.5.
  218.     set f to (f + 1).
  219. }.
  220.  
  221. }.
  222. }. else {
  223.     Print "You are not ready to launch or not on the Launchpad.".
  224.     Print  "Your Status is: " + Status.
  225.     WAIT UNTIL FALSE.
  226. }.
  227.  
  228.  
  229. //end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement