Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==CMLS SUICIDE BURN SCRIPT==
- SET scriptVersion TO "v0.2.0".
- //0.1.0
- // - First stable version
- //
- //0.1.1
- //--Major improvements--
- // - Experimental PI controller
- // - Automatic engine activation and deactivation handling
- // - Automatic Kp adjustment based on TWR
- //--Minor improvements--
- // - Exported initial engine setup to shutdown script
- // - Added PILOTMAINTHROTTLE control to ensure that the
- // booster doesn't revert to half or full throttle once
- // the script ends
- //
- //0.2.0
- //--Major improvements--
- // - Automatic opMode checking to handle the different
- // types of cores (side booster vs S1)
- // - Reverted to P controller for simplicity; PI controller
- // did not improve results and was difficult to tune
- // - Automatic handling of occasionally-necessary
- // re-entry burn based on speed and remaining delta-v
- //--Minor improvements--
- // - Replaced shutdown script with the same CMLSeng script
- // that handles the engine tagging and shutdown for the
- // launch sequence. Updated launch scripts to
- // automatically copy that script to the core/booster
- // computers
- // - Added remaining delta-v and booster type readouts
- // - Moved altitude triggers outside of control loop
- //~~~~~SPLASHSCREEN~~~~~
- SET TERMINAL:WIDTH TO 50.
- SET TERMINAL:HEIGHT TO 25.
- CLEARSCREEN.
- PRINT "==========COYOTE MLS SUICIDE BURN SCRIPT==========".
- PRINT "----------------------" + scriptVersion + "----------------------".
- WAIT 1.
- PRINT "Initializing...".
- RUN CMLSeng.
- //~~~~~Variable Declaration~~~~~
- SET nextLine TO 7. //Tracks next line that events should print at in the event log
- IF SHIP:PARTSTAGGED("S1Alpha"):LENGTH > 0 {
- SET opMode TO "Core".
- } ELSE IF SHIP:PARTSTAGGED("LBAlpha"):LENGTH > 0 {
- SET opMode TO "LeftBooster".
- } ELSE IF SHIP:PARTSTAGGED("RBAlpha"):LENGTH > 0 {
- SET opMode TO "RightBooster".
- }. //IF-ELSE opMode
- FOR eng IN engAll {
- IF eng:GETMODULE("ModuleEnginesFX"):HASEVENT("Shutdown Engine") { //Shutdown all engines
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").
- }.
- }.
- IF opMode = "Core" {
- S1Alpha:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate alpha-group engines
- FOR eng IN S1Bravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate bravo-group engines
- }. //FOR eng
- } ELSE IF opMode = "LeftBooster" {
- LBAlpha:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate alpha-group engines
- FOR eng IN LBBravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate bravo-group engines
- }. //FOR eng
- } ELSE IF opMode = "RightBooster" {
- RBAlpha:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate alpha-group engines
- FOR eng IN RBBravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Activate bravo-group engines
- }. //FOR eng
- }. //IF opMode
- RCS ON.
- GEAR OFF.
- SET thrott TO 0.
- SET I TO 0.
- SET SBSAmargin TO 10. //Margin to allow for burns that start a little too late
- LOCK dvRemain TO (engAll[0]:ISP * CONSTANT():G) * LN(SHIP:MASS / SHIP:DRYMASS). //Keeps track of remaining delta-v
- 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
- WAIT 2.5.
- //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 "OPM: " AT(0,3). //Readout at 6,3
- PRINT opMode AT(6,3). //opMode readout; static from script start
- PRINT "DVR: " AT(33,3). //Readout at 39,3
- PRINT "--------------------EVENT LOG---------------------" AT(0,5).
- PRINT "Stage ready for boostback burn" AT(0,nextLine).
- SET nextLine to nextLine + 1.
- //~~~~~Boostback completion~~~~~
- WAIT UNTIL vsActual < 0. //Wait until apogee
- WAIT 10. //Wait another 10 seconds to allow for late/extended boostback burns
- FOR eng IN S1Bravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine"). //Shutdown bravo-group engines, this leaves the single alpha engine running
- }.
- FOR eng IN LBBravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").
- }.
- FOR eng IN RBBravo {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").
- }.
- PRINT "Stage prepared for re-entry." AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- WAIT UNTIL ALTITUDE < 15000.
- IF VELOCITY:SURFACE:MAG > 1400 AND dvRemain >= 550 {
- PRINT "Re-entry velocity high;" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- PRINT "Performing re-entry burn" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.5.
- WAIT UNTIL dvRemain < 500.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- PRINT "Re-entry burn complete" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- } ELSE IF VELOCITY:SURFACE:MAG > 1400 AND dvRemain < 550 {
- PRINT "Re-entry velocity high;" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- PRINT "Delta-V margin below threshold; no re-entry burn" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //IF-ELSE surf velocity
- SAS OFF.
- LOCK Kp TO (TWR * -0.3) + 1.3. //Adjusts the gain based on the TWR
- LOCK P to (vsSetpoint - vsActual). //Error - difference between desired VS and actual VS
- LOCK THROTTLE TO thrott.
- LOCK dthrott TO Kp * P.
- LOCK SBSA TO (((vsActual^2) / (2 * (SHIP:MAXTHRUST / SHIP:MASS) - SHIP:SENSORS:GRAV:MAG)) + SBSAmargin). //Determines suicide burn start altitude
- //~~~~~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
- 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
- //~~~~~P Loop/Readouts~~~~~
- UNTIL STATUS = "LANDED" { //Loops until touchdown
- SET thrott TO thrott + dthrott.
- 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 dvRemain + " " AT(39,3). //Prints remaining DV
- WAIT 0.001.
- }. //UNTIL
- PRINT "Touchdown!" at (0,nextLine).
- SET nextLine TO nextLine + 1.
- SAS OFF.
- RCS OFF.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement