Advertisement
space_is_hard

CMLSsburn 0.1.5

Mar 23rd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.61 KB | None | 0 0
  1. //==CMLS SUICIDE BURN SCRIPT==
  2.  
  3. SET scriptVersion TO "v0.1.5".
  4.  
  5. //~~~~~SPLASHSCREEN~~~~~
  6.  
  7. SET TERMINAL:WIDTH TO 50.
  8. SET TERMINAL:HEIGHT TO 25.
  9. CLEARSCREEN.
  10.  
  11. PRINT "==========COYOTE MLS MK1R SUICIDE BURN============".
  12. PRINT "----------------------" + scriptVersion + "----------------------".
  13. WAIT 1.
  14.  
  15. PRINT "Initializing...".
  16.  
  17. SET ready TO FALSE.
  18.  
  19. COPY shutdown FROM 0.       //Runs engine shutdown script; required for the engine activation commands to work
  20. RUN shutdown.
  21.  
  22. SET nextLine TO 6.      //Tracks next line that events should print at in the event log
  23.  
  24. SET engine1S1 TO SHIP:PARTSTAGGED("E1S1")[0].           //Engine 1, stage 1
  25. SET engine2S1 TO SHIP:PARTSTAGGED("E2S1")[0].           //Engine 2, stage 1
  26. SET engine3S1 TO SHIP:PARTSTAGGED("E3S1")[0].           //And so on...
  27. SET engine4S1 TO SHIP:PARTSTAGGED("E4S1")[0].
  28. SET engine5S1 TO SHIP:PARTSTAGGED("E5S1")[0].
  29. SET engine6S1 TO SHIP:PARTSTAGGED("E6S1")[0].
  30. SET engine7S1 TO SHIP:PARTSTAGGED("E7S1")[0].
  31.  
  32. RCS ON.
  33. GEAR OFF.
  34. engine1S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine").        //Activate the three boostback engines
  35. engine2S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine").
  36. engine3S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine").
  37.  
  38. SET thrott TO 0.
  39. SET I TO 0.
  40.  
  41. SET SBSAmargin TO 10.       //Margin to allow for burns that start a little too late
  42.  
  43. LOCK TWR TO SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG).       //Keeps track of TWR
  44.  
  45. LOCK vsActual TO SHIP:VERTICALSPEED.
  46. SET radaltOffset TO 18.4.       //Fixed offset amount from probe core to landing legs
  47. LOCK radaltActual TO (ALT:RADAR - radaltOffset).        //Uses offset amount to track distance from bottom of landing legs to ground.
  48.  
  49. SET vsSetpoint TO -10000.       //Starts out really low so that the PI doesn't try to adjust the vertical speed whilst falling back to the launch site
  50.  
  51. LOCK Kp TO (TWR * -0.3) + 1.        //Adjusts the gain based on the TWR
  52. SET Ki TO 0.01.
  53.  
  54. LOCK P to (vsSetpoint - vsActual).
  55.  
  56. WAIT 1.
  57.  
  58. //Readout header
  59. CLEARSCREEN.
  60. PRINT "==========COYOTE MLS MK1R SUICIDE BURN============" AT(0,0).
  61. PRINT "TWR: " AT(0,2).          //Readout at 6,2
  62. PRINT "BSA: " AT(16,2).         //Readout at 22,2
  63. PRINT "ARA: " AT(33,2).         //Readout at 39,2
  64. PRINT "--------------------EVENT LOG---------------------" AT(0,4).
  65. PRINT "Stage ready for boostback burn" AT(0,nextLine).
  66. SET nextLine to nextLine + 1.
  67.  
  68. //~~~~~Boostback completion~~~~~
  69. WAIT UNTIL vsActual < 0.        //Wait until apogee
  70. WAIT 30.        //Wait another 30 seconds to allow for late/extended boostback burns
  71.  
  72. engine2S1:GETMODULE("ModuleEngines"):DOEVENT("Shutdown Engine").        //Shutdown both active perimiter engines; only center should remain active
  73. engine3S1:GETMODULE("ModuleEngines"):DOEVENT("Shutdown Engine").
  74.  
  75. PRINT "Stage prepared for re-entry." AT(0,nextLine).
  76. SET nextLine TO nextLine + 1.
  77.  
  78. SAS OFF.
  79. LOCK THROTTLE TO thrott.
  80. LOCK dthrott TO Kp * P + Ki * I.
  81. SET t0 TO TIME:SECONDS.
  82.  
  83. LOCK SBSA TO (((vsActual^2) / (2 * (SHIP:MAXTHRUST / SHIP:MASS) - SHIP:SENSORS:GRAV:MAG)) + SBSAmargin).        //Determines suicide burn start altitude
  84.  
  85. //~~~~~Suicide Burn control~~~~~
  86.  
  87. WHEN radaltActual < (SBSA + 250) THEN {     //Waits until 250m above SBSA
  88.     SAS ON.
  89.     PRINT "Prepare for suicide burn." AT(0,nextLine).
  90.     SET nextLine TO nextLine + 1.
  91.  
  92.     WHEN radaltActual < SBSA THEN {     //Waits until SBSA
  93.         LOCK vsSetpoint TO -3.      //Stage will burn fully until 3m/s descent
  94.         SET ready TO TRUE.      //Initiates PI loop
  95.         GEAR ON.
  96.         PRINT "Suicide burn initiated. Gear down." AT(0,nextLine).
  97.         SET nextLine TO nextLine + 1.
  98.        
  99.         WHEN radaltActual < 10 THEN {       //Below 10 meters, it switches to 1m/s descent
  100.             LOCK vsSetpoint TO -1.
  101.  
  102.         }. //WHEN < 10
  103.     }. //WHEN < SBSA
  104. }. //WHEN < 250 + SBSA
  105.  
  106. UNTIL STATUS = "LANDED" {       //Loops until touchdown
  107.    
  108.     IF ready = TRUE {       //PI loop is initiated when ready is set to true
  109.         SET dt TO TIME:SECONDS - t0.
  110.        
  111.         IF dt > 0 {
  112.             SET I TO I + P * dt.
  113.             SET thrott TO thrott + dthrott.
  114.             SET t0 TO TIME:SECONDS.
  115.            
  116.         }. //IF dt
  117.     }. //IF ready
  118.  
  119.     //Readout updater
  120.     PRINT ROUND(TWR,1) + "    " AT(6,2).        //Prints TWR
  121.     PRINT ROUND(SBSA,1) + "    " AT(22,2).      //Prints suicide burn start alt
  122.     PRINT ROUND(radaltActual,1) + "    " AT(39,2).      //Prints the radar altitude adjusted for the landing legs
  123.    
  124. //  PRINT ROUND(vsSetpoint,1) + "VSet  " AT(0,25).      //For debugging purposes
  125. //  PRINT ROUND(thrott,2) + "thrt  " AT(16,25).
  126. //  PRINT ROUND(dthrott,2) + "dthrt  " AT(33,25).
  127.     WAIT 0.001.
  128.  
  129. }. //UNTIL
  130.  
  131. PRINT "Touchdown!" at (0,nextLine).
  132. SET nextLine TO nextLine + 1.
  133. SAS OFF.
  134. RCS OFF.
  135. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.        //Ensures that the throttle is zero when the script ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement