Advertisement
space_is_hard

CMLSrun 0.1.0

Mar 27th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.66 KB | None | 0 0
  1. //CoyLaunch Master Script
  2.  
  3. SET scriptVersion TO "0.1.0".
  4.  
  5. //TODO:
  6. // - Get vehicle type
  7. // - Get desired apoapsis
  8. // - Copy relevant scripts
  9. // - Run launch for that vehicle type
  10.  
  11. //HOW TO IMPLEMENT:
  12. // - Use thrust plate tag to determine vehicle type
  13. // - Use declared apoapsis
  14. // - Copy over sburn script if necessary
  15. // - Copy over launch staging script
  16. // - Copy over readout script
  17. // - Copy over engine tag script
  18. // - Run engine tag script + shutdown all engines
  19. // - Perform countdown + liftoff
  20. // - Run launch script
  21. // - Run readout script
  22. // - Kill everything when desapo reached
  23.  
  24. DECLARE targetAlt.
  25.  
  26. SET TERMINAL:WIDTH TO 50.
  27. SET TERMINAL:HEIGHT TO 25.
  28. CLEARSCREEN.
  29.  
  30. PRINT "========COYOTE MLS LAUNCH CONTROLLER SCRIPT=======".
  31. PRINT "----------------------" + scriptVersion + "----------------------".
  32. WAIT 0.25.
  33. PRINT "Initializing...".
  34.  
  35. //~~~~~Variables~~~~~
  36. SET countdown TO 10.        //Length of countdown. Minimum of five seconds required.
  37. SET CDmessage TO " ".       //Holds messages for countdown loop
  38. SET nextLine TO 7.      //Handles event log printing after liftoff
  39. SET fairingSep TO FALSE.        //Variable to view fairing separation status; false = still attached
  40. SET BECOtimer TO 10000.     //Marks BECO time
  41. SET S1ECOtimer TO 10000.        //Marks S1ECO time
  42. SET SBSepLevel TO 0.        //Percent of fuel desired for booster RTLS.
  43. SET S1SepLevel TO 0.        //Percent of fuel desired for first stage RTLS.
  44. SET activeStage TO "1".     //Variable to view active stage
  45. SET updateRes TO 10.        //Determines how many refreshes per second for the readout script
  46.  
  47. //~~~~~Script management and more variables~~~~~
  48.  
  49. IF SHIP:PARTSTAGGED("Mk1"):LENGTH > 0 {
  50.     SET opMode TO "1".
  51.     COPY CMLS1.ksm FROM 0.
  52.    
  53. } ELSE IF SHIP:PARTSTAGGED("Mk1R"):LENGTH > 0 {
  54.     SET opMode TO "1R".
  55.     COPY CMLS1.ksm FROM 0.
  56. //  COPY CMLSSBURN FROM 0.
  57. //  COPY CMLSSBURN TO 2.
  58. //  DELETE CMLSSBURN FROM 1.
  59.    
  60.     SET S1SepLevel TO 15.
  61.  
  62. } ELSE IF SHIP:PARTSTAGGED("Mk2"):LENGTH > 0 {
  63.     SET opMode TO "2".
  64.     COPY CMLS2.ksm FROM 0.
  65.    
  66.     SET activeStage TO "1B".
  67.    
  68. } ELSE IF SHIP:PARTSTAGGED("Mk2RB"):LENGTH > 0 {
  69.     SET opMode TO "2RB".
  70.     COPY CMLS2.ksm FROM 0.
  71. //  COPY CMLSSBURN TO 3.
  72. //  COPY CMLSSBURN TO 4.
  73. //  DELETE CMLSSBURN FROM 1.
  74.  
  75.     SET activeStage TO "1B".
  76.     SET SBSepLevel TO 15.
  77.    
  78. } ELSE IF SHIP:PARTSTAGGED("Mk2R"):LENGTH > 0 {
  79.     SET opMode TO "2R".
  80.     COPY CMLS2.ksm FROM 0.
  81. //  COPY CMLSSBURN TO 2.
  82. //  COPY CMLSSBURN TO 3.
  83. //  COPY CMLSSBURN TO 4.
  84. //  DELETE CMLSSBURN FROM 1.
  85.    
  86.     SET activeStage TO "1B".
  87.     SET SBSepLevel TO 15.
  88.     SET S1SepLevel TO 20.
  89.    
  90. }. //IF
  91.  
  92. SWITCH TO 0.
  93. RUN CMLSeng.        //Tags all engines and shuts down any running
  94. SWITCH TO 1.
  95.  
  96. //~~~~~Parts~~~~~
  97. SET interStage TO SHIP:PARTSTAGGED("intstage")[0].      //Interstage fairing and decoupler between first and second stage
  98. SET fairingShell TO SHIP:PARTSTAGGED("fairinghalf").        //Both fairing halves
  99.  
  100.  
  101. IF opMode = "2RB" OR opMode = "2R" {
  102.     SET SBAnt TO SHIP:PARTSTAGGED("SBAnt").     //Small omnidirectional antennae for booster communication
  103. }. //IF opMode antenna
  104. IF opMode = "1R" OR opMode = "2R" {
  105.     SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0].      //Small omnidirectional antenna for first stage communication
  106.     SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge").
  107. }. //IF opMode antenna
  108. SET S2Ant TO SHIP:PARTSTAGGED("S2Ant")[0].      //Small omnidirectional antenna for second stage communication
  109.  
  110. SET lClamps TO SHIP:PARTSDUBBED("launchclamp1").        //Launch clamps holding first stage/boosters down
  111. FOR part IN lClamps {
  112.     part:GETMODULE("RefuelingPump"):DOEVENT("Toggle Pump").     //Turn on fuel pump to keep stage topped off
  113. }. //FOR lClamps pump
  114.  
  115. SET S2Tank TO SHIP:PARTSTAGGED("S2Tank")[0].
  116. SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0].
  117. IF opMode = "1" OR opMode = "1R" {
  118.     FOR res IN S1Tank:RESOURCES {
  119.         IF res:NAME = "LQDOXYGEN" {
  120.             SET S1LOX TO res.
  121.             SET loxCap TO S1LOX:CAPACITY.
  122.            
  123.         }. //IF res
  124.     }. //FOR res
  125.    
  126.     LOCK loxAmount TO S1LOX:AMOUNT.
  127.    
  128. } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" {
  129.     SET SBDecouplers TO SHIP:PARTSTAGGED("SBDecoup").
  130.    
  131.     SET LBTank[0] TO SHIP:PARTSTAGGED("LBTankA")[0].
  132.     SET LBTank[1] TO SHIP:PARTSTAGGED("LBTankB")[0].
  133.     SET RBTank[0] TO SHIP:PARTSTAGGED("RBTankA")[0].
  134.     SET RBTank[1] TO SHIP:PARTSTAGGED("RBTankB")[0].
  135.    
  136.     FOR res IN LBTank[0]:RESOURCES {
  137.         IF res:NAME = "LQDOXYGEN" {
  138.             SET LBLOX[0] TO res.
  139.         }. //IF res
  140.     }. //FOR res
  141.    
  142.     FOR res IN LBTank[1]:RESOURCES {
  143.         IF res:NAME = "LQDOXYGEN" {
  144.             SET LBLOX[1] TO res.
  145.         }. //IF res
  146.     }. //FOR res
  147.    
  148.     FOR res IN RBTank[0]:RESOURCES {
  149.         IF res:NAME = "LQDOXYGEN" {
  150.             SET RBLOX[0] TO res.
  151.         }. //IF res
  152.     }. //FOR res
  153.    
  154.     FOR res IN RBTank[1]:RESOURCES {
  155.         IF res:NAME = "LQDOXYGEN" {
  156.             SET RBLOX[1] TO res.
  157.         }. //IF res
  158.     }. //FOR res
  159.    
  160.     SET loxCap TO (LBLOX[0]:CAPACITY + LBLOX[1]:CAPACITY + RBLOX[0]:CAPACITY + RBLOX[1]:CAPACITY).
  161.     LOCK loxAmount TO MIN((LBLOX[0]:AMOUNT + LBLOX[1]:AMOUNT),(RBLOX[0]:AMOUNT + RBLOX[1]:AMOUNT)).
  162.    
  163. }. //IF-ELSE loxCap
  164. LOCK loxRemaining TO (loxAmount / (loxCap + 0.01)).     //Locks percentage of fuel left in stage +0.01 to avoid divide by zero/NaN
  165.  
  166. PRINT "Awaiting launch. Press Action Group 0 to start " + countdown + "-second countdown".
  167. AG10 OFF.
  168. WAIT UNTIL AG10.
  169.  
  170. //~~~~~Countdown sequence~~~~~
  171.  
  172. PRINT "Countdown sequence started".
  173.  
  174. UNTIL countdown = 0 {       //Countdown loop
  175.     IF countdown = 3 {
  176.         FOR eng IN engAll {
  177.             eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").
  178.         }. //FOR eng
  179.         SET message TO " Main Engine Start".
  180.         SET BEItime to TIME:SECONDS.        //Records BEI time
  181.  
  182.     } ELSE IF countdown = 2 {
  183.         SET message TO " All engines healthy".
  184.         SAS ON.
  185.  
  186.     } ELSE IF countdown = 1 {
  187.         SET message TO " Releasing clamps".
  188.  
  189.     } ELSE {
  190.         SET message TO " ".
  191.    
  192.     }. //IF countdown message      
  193.  
  194.     PRINT "T-" + countdown + message.
  195.     SET countdown TO countdown - 1.
  196.     WAIT 1.
  197.    
  198. }. //UNTIL countdown
  199.  
  200. FOR PART IN lClamps {       //Loop to release launch clamps
  201.     PART:GETMODULE("launchclamp"):DOEVENT("release clamp").
  202. }. //FOR lClamps release
  203.  
  204. SET launchTime TO TIME:SECONDS.     //Records liftoff time
  205. LOCK missionClock TO ROUND((TIME:SECONDS - launchTime), 1).     //Sets missionClock to T-0 and starts counting, rounded to tenths of a second
  206.  
  207. CLEARSCREEN.
  208. PRINT "============COYOTE MEDIUM LAUNCH SYSTEM===========" AT(0,0).
  209.  
  210. PRINT "ASL: " AT(0,2).      //Altitude above sea level readout at 6,2
  211. PRINT "VEL: " AT(16,2).     //Surface or orbital velocity readout at 22,2
  212. PRINT "CLK: " AT(33,2).     //Mission clock readout at 39,2
  213.  
  214. PRINT "STG: " AT(0,3).      //Current stage readout at 6,3
  215. PRINT "SFL: " AT(16,3).     //Stage fuel level readout at 22,3
  216. PRINT "FRG: " AT(33,3).     //Fairing status readout at 39,3
  217.  
  218. PRINT "-------------------EVENT LOG----------------------" AT(0,5).
  219.  
  220. PRINT "T-" + ROUND(ABS(BEItime - launchTime),2) + " BEI" AT(0,nextLine).        //Time of BEI, will be negative
  221. SET nextLine TO nextLine + 1.
  222. PRINT "T+0.0 Liftoff" AT(0,nextLine).
  223. SET nextLine TO nextLine + 1.
  224.  
  225. IF opMode = "1" OR opMode = "1R" {
  226.     RUN CMLS1.ksm.
  227. } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" {
  228.     RUN CMLS2.
  229. }.
  230.  
  231. UNTIL SHIP:APOAPSIS >= (targetAlt * 1000) {
  232.     PRINT FLOOR(SHIP:ALTITUDE) + "   " AT(6,2).
  233.  
  234.     IF ALTITUDE <=50000 {       //Prints surface velocity below 50km, orbital above
  235.         PRINT ROUND(VELOCITY:SURFACE:MAG,1) + "   " AT(22,2).
  236.     } ELSE {
  237.         PRINT ROUND(VELOCITY:ORBIT:MAG,1) + "   " AT(22,2).
  238.     }. //IF-ELSE
  239.  
  240.     PRINT missionClock AT(39,2).
  241.     PRINT activeStage AT(6,3).
  242.     PRINT ROUND((loxRemaining * 100), 1) + "%  " AT(22,3).
  243.  
  244.     IF fairingSep = FALSE {         //Prints ATCHD or SPRTD depending on whether the fairings are still on
  245.         PRINT "ATCHD" + "   " AT(39,3).
  246.     } ELSE {
  247.         PRINT "SPRTD" + "   " AT(39,3).
  248.     }. //IF-ELSE
  249.  
  250.     WAIT (1 / updateRes).       //Update resolution turned into fraction
  251.    
  252. }. //UNTIL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement