Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==CMLS SUICIDE BURN SCRIPT==
- SET scriptVersion TO "v0.1.5".
- //~~~~~SPLASHSCREEN~~~~~
- SET TERMINAL:WIDTH TO 50.
- SET TERMINAL:HEIGHT TO 25.
- CLEARSCREEN.
- PRINT "==========COYOTE MLS MK1R SUICIDE BURN============".
- PRINT "----------------------" + scriptVersion + "----------------------".
- WAIT 1.
- PRINT "Initializing...".
- SET ready TO FALSE.
- COPY shutdown FROM 0. //Runs engine shutdown script; required for the engine activation commands to work
- RUN shutdown.
- SET nextLine TO 6. //Tracks next line that events should print at in the event log
- SET engine1S1 TO SHIP:PARTSTAGGED("E1S1")[0]. //Engine 1, stage 1
- SET engine2S1 TO SHIP:PARTSTAGGED("E2S1")[0]. //Engine 2, stage 1
- SET engine3S1 TO SHIP:PARTSTAGGED("E3S1")[0]. //And so on...
- SET engine4S1 TO SHIP:PARTSTAGGED("E4S1")[0].
- SET engine5S1 TO SHIP:PARTSTAGGED("E5S1")[0].
- SET engine6S1 TO SHIP:PARTSTAGGED("E6S1")[0].
- SET engine7S1 TO SHIP:PARTSTAGGED("E7S1")[0].
- RCS ON.
- GEAR OFF.
- engine1S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine"). //Activate the three boostback engines
- engine2S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine").
- engine3S1:GETMODULE("ModuleEngines"):DOEVENT("Activate Engine").
- SET thrott TO 0.
- SET I TO 0.
- SET SBSAmargin TO 10. //Margin to allow for burns that start a little too late
- LOCK TWR TO SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG). //Keeps track of TWR
- LOCK vsActual TO SHIP:VERTICALSPEED.
- SET radaltOffset TO 18.4. //Fixed offset amount from probe core to landing legs
- LOCK radaltActual TO (ALT:RADAR - radaltOffset). //Uses offset amount to track distance from bottom of landing legs to ground.
- 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
- LOCK Kp TO (TWR * -0.3) + 1. //Adjusts the gain based on the TWR
- SET Ki TO 0.01.
- LOCK P to (vsSetpoint - vsActual).
- WAIT 1.
- //Readout header
- CLEARSCREEN.
- PRINT "==========COYOTE MLS MK1R SUICIDE BURN============" AT(0,0).
- PRINT "TWR: " AT(0,2). //Readout at 6,2
- PRINT "BSA: " AT(16,2). //Readout at 22,2
- PRINT "ARA: " AT(33,2). //Readout at 39,2
- PRINT "--------------------EVENT LOG---------------------" AT(0,4).
- PRINT "Stage ready for boostback burn" AT(0,nextLine).
- SET nextLine to nextLine + 1.
- //~~~~~Boostback completion~~~~~
- WAIT UNTIL vsActual < 0. //Wait until apogee
- WAIT 30. //Wait another 30 seconds to allow for late/extended boostback burns
- engine2S1:GETMODULE("ModuleEngines"):DOEVENT("Shutdown Engine"). //Shutdown both active perimiter engines; only center should remain active
- engine3S1:GETMODULE("ModuleEngines"):DOEVENT("Shutdown Engine").
- PRINT "Stage prepared for re-entry." AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- SAS OFF.
- LOCK THROTTLE TO thrott.
- LOCK dthrott TO Kp * P + Ki * I.
- SET t0 TO TIME:SECONDS.
- LOCK SBSA TO (((vsActual^2) / (2 * (SHIP:MAXTHRUST / SHIP:MASS) - SHIP:SENSORS:GRAV:MAG)) + SBSAmargin). //Determines suicide burn start altitude
- //~~~~~Suicide Burn control~~~~~
- WHEN radaltActual < (SBSA + 250) THEN { //Waits until 250m above SBSA
- SAS ON.
- PRINT "Prepare for suicide burn." AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- WHEN radaltActual < SBSA THEN { //Waits until SBSA
- LOCK vsSetpoint TO -3. //Stage will burn fully until 3m/s descent
- SET ready TO TRUE. //Initiates PI loop
- GEAR ON.
- PRINT "Suicide burn initiated. Gear down." AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- WHEN radaltActual < 10 THEN { //Below 10 meters, it switches to 1m/s descent
- LOCK vsSetpoint TO -1.
- }. //WHEN < 10
- }. //WHEN < SBSA
- }. //WHEN < 250 + SBSA
- UNTIL STATUS = "LANDED" { //Loops until touchdown
- IF ready = TRUE { //PI loop is initiated when ready is set to true
- SET dt TO TIME:SECONDS - t0.
- IF dt > 0 {
- SET I TO I + P * dt.
- SET thrott TO thrott + dthrott.
- SET t0 TO TIME:SECONDS.
- }. //IF dt
- }. //IF ready
- //Readout updater
- PRINT ROUND(TWR,1) + " " AT(6,2). //Prints TWR
- PRINT ROUND(SBSA,1) + " " AT(22,2). //Prints suicide burn start alt
- PRINT ROUND(radaltActual,1) + " " AT(39,2). //Prints the radar altitude adjusted for the landing legs
- // PRINT ROUND(vsSetpoint,1) + "VSet " AT(0,25). //For debugging purposes
- // PRINT ROUND(thrott,2) + "thrt " AT(16,25).
- // PRINT ROUND(dthrott,2) + "dthrt " AT(33,25).
- WAIT 0.001.
- }. //UNTIL
- PRINT "Touchdown!" at (0,nextLine).
- SET nextLine TO nextLine + 1.
- SAS OFF.
- RCS OFF.
- 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