Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==Coyote Medium LS Launch script 2, 2RB and 2R==
- SET scriptVersion TO "v0.2.2". //Version control
- //~~CHANGELOG:~~
- //0.1.0
- // - First stable version
- //
- //0.2.0
- //--Major improvements--
- // - Added declared opMode to control vehicle version/
- // operation mode
- // - Added staging control for Mk2 versions
- //--Minor improvements--
- // - Improved handling of engines and activations/
- // shutdowns
- // - Improved fuel tank/fuel level handling
- // - All fuel pumps will now be turned on before liftoff in
- // order to keep
- // the boosters topped off in addition to the first and
- // second stages
- // - Removed redundant timers; antenna activation now oc-
- // curs on fairing separation
- // - Removed unused "exit loop"
- // - Switched liftoff handling to action group that starts
- // a configurable countdown
- // - Changed script exit parameters; target apoapsis alti-
- // tude is declared on start and script closes when it is
- // reached. A proper ascent should allow for a healthy
- // periapsis by this time.
- //
- //0.2.1
- //--Major improvements--
- // - Separated 1/1R versions from 2/2RB/2R versions to de-
- // crease script size.
- //--Minor improvements--
- // - Automatically determined opMode
- //
- //0.2.2
- //--Major improvements--
- // - Added mechanism to reduce throttles on charlie-group
- // engines to 50% when TWR first climbs above 3g
- //--Minor improvements--
- // - Added lock variable to track TWR
- // - Throttle automatically sets itself to full during
- // start sequence and cuts off when target apoapsis is
- // reached
- //FUTURE SUBVERSION TODO:
- // - Change engine startup/shutdown handling to use
- // DOACTION instead of DOEVENT
- // - Fault checking
- // - Abort conditions and abort automation for future man-
- // ned variant
- // - Expanded readouts
- // - Launch guidance assist (display vectors to aid manual
- // control)
- // - Launch guidance automation (completely automate
- // launch, one button press to orbit)
- DECLARE PARAMETER targetAlt.
- SET TERMINAL:WIDTH TO 50.
- SET TERMINAL:HEIGHT TO 25.
- CLEARSCREEN.
- PRINT "========COYOTE MLS LAUNCH CONTROLLER SCRIPT=======".
- PRINT "----------------------" + scriptVersion + "----------------------".
- WAIT 0.25.
- PRINT "Initializing...".
- //~~~~~Variables~~~~~
- SET countdown TO 10. //Length of countdown. Minimum of five seconds required.
- SET CDmessage TO " ". //Holds messages for countdown loop
- SET nextLine TO 7. //Handles event log printing after liftoff
- SET fairingSep TO FALSE. //Variable to view fairing separation status; false = still attached
- SET BECOtimer TO 10000. //Marks BECO time
- SET S1ECOtimer TO 10000. //Marks S1ECO time
- SET SBSepLevel TO 0. //Percent of fuel desired for side booster RTLS.
- SET S1SepLevel TO 0. //Percent of fuel desired for first stage RTLS.
- SET activeStage TO "1B". //Variable to view active stage, Mk2 versions start at 1B (booster)
- SET updateRes TO 10. //Determines how many refreshes per second for the readout script
- //~~~~~Script management and more variables~~~~~
- IF SHIP:PARTSTAGGED("Mk2"):LENGTH > 0 {
- SET opMode TO "2".
- } ELSE IF SHIP:PARTSTAGGED("Mk2RB"):LENGTH > 0 {
- SET opMode TO "2RB".
- COPY CMLSsburn.ksm FROM 0.
- COPY CMLSsburn.ksm TO 2.
- COPY CMLSsburn.ksm TO 3.
- DELETE CMLSsburn.ksm FROM 1.
- COPY CMLSeng.ksm FROM 0.
- COPY CMLSeng.ksm TO 2.
- COPY CMLSeng.ksm TO 3.
- DELETE CMLSeng.ksm FROM 1.
- SET SBSepLevel TO 15.
- } ELSE IF SHIP:PARTSTAGGED("Mk2R"):LENGTH > 0 {
- SET opMode TO "2R".
- COPY CMLSsburn.ksm FROM 0.
- COPY CMLSsburn.ksm TO 2.
- COPY CMLSsburn.ksm TO 3.
- COPY CMLSsburn.ksm TO 4.
- DELETE CMLSsburn.ksm FROM 1.
- COPY CMLSeng.ksm FROM 0.
- COPY CMLSeng.ksm TO 2.
- COPY CMLSeng.ksm TO 3.
- COPY CMLSeng.ksm TO 4.
- DELETE CMLSeng.ksm FROM 1.
- SET SBSepLevel TO 15.
- SET S1SepLevel TO 20.
- }. //IF
- SWITCH TO 0.
- RUN CMLSeng. //Tags all engines and shuts down any running
- SWITCH TO 1.
- //~~~~~Parts~~~~~
- SET interStage TO SHIP:PARTSTAGGED("intstage")[0]. //Interstage fairing and decoupler between first and second stage
- SET fairingShell TO SHIP:PARTSTAGGED("fairinghalf"). //Both fairing halves
- IF opMode = "2RB" OR opMode = "2R" {
- SET SBAnt TO SHIP:PARTSTAGGED("SBAnt"). //Small omnidirectional antennae for booster communication
- SET SBfinHinges TO SHIP:PARTSTAGGED("SBFinHinge"). //Side booster fin hinges, only on 2RB or 2R
- }. //IF opMode
- IF opMode = "2R" {
- SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0]. //Small omnidirectional antenna for first stage communication
- SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge"). //Stage 1 fin hinges, only on 2R
- }. //IF opMode
- SET S2Ant TO SHIP:PARTSTAGGED("S2Ant")[0]. //Small omnidirectional antenna for second stage communication
- SET lClamps TO SHIP:PARTSDUBBED("launchclamp1"). //Launch clamps holding first stage/boosters down
- FOR part IN lClamps {
- part:GETMODULE("RefuelingPump"):DOEVENT("Toggle Pump"). //Turn on fuel pump to keep stage topped off
- }. //FOR lClamps pump
- SET S2Tank TO SHIP:PARTSTAGGED("S2Tank")[0]. //Stage 2 fuel tank
- SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0]. //Stage 2 fuel tank
- FOR res IN S1Tank:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET S1LOX TO res.
- SET loxCap TO S1LOX:CAPACITY. //Sets lox capacity for stage 1 tank
- }. //IF res
- }. //FOR res
- SET SBDecouplers TO SHIP:PARTSTAGGED("SBDecoup").
- SET LBTank[0] TO SHIP:PARTSTAGGED("LBTankA")[0]. //Left booster main tank
- SET LBTank[1] TO SHIP:PARTSTAGGED("LBTankB")[0]. //Left booster extension tank
- SET RBTank[0] TO SHIP:PARTSTAGGED("RBTankA")[0]. //Right booster main tank
- SET RBTank[1] TO SHIP:PARTSTAGGED("RBTankB")[0]. //Right booster extension tank
- FOR res IN LBTank[0]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET LBLOX[0] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN LBTank[1]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET LBLOX[1] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN RBTank[0]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET RBLOX[0] TO res.
- }. //IF res
- }. //FOR res
- FOR res IN RBTank[1]:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET RBLOX[1] TO res.
- }. //IF res
- }. //FOR res
- SET loxCap TO (LBLOX[0]:CAPACITY + LBLOX[1]:CAPACITY + RBLOX[0]:CAPACITY + RBLOX[1]:CAPACITY).
- LOCK loxAmount TO MIN((LBLOX[0]:AMOUNT + LBLOX[1]:AMOUNT),(RBLOX[0]:AMOUNT + RBLOX[1]:AMOUNT)). //Locks remaining LOX amount to the lesser of the two side booster tanks (two tanks on each booster)
- LOCK loxRemaining TO (loxAmount / (loxCap + 0.01)). //Locks percentage of fuel left in stage +0.01 to avoid divide by zero/NaN
- //~~~~~Countdown sequence~~~~~
- PRINT "Awaiting launch. Press Action Group 0 to start " + countdown + "-second countdown".
- AG10 OFF.
- WAIT UNTIL AG10.
- PRINT "Countdown sequence started".
- UNTIL countdown = 0 { //Countdown loop
- IF countdown = 3 { //Engines activate at T-3
- FOR eng IN engAll {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").
- }. //FOR eng
- SET message TO " Main Engine Start".
- SET BEItime to TIME:SECONDS. //Records BEI time
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 1. //Set throttle to 100%
- } ELSE IF countdown = 2 {
- SET message TO " All engines healthy".
- SAS ON.
- } ELSE IF countdown = 1 {
- SET message TO " Releasing clamps".
- } ELSE {
- SET message TO " ". //Clears message variable if no event is happening that tick
- }. //IF countdown message
- PRINT "T-" + countdown + message. //Prints any message handed off by countdown
- SET countdown TO countdown - 1.
- WAIT 1.
- }. //UNTIL countdown
- LOCK TWR TO SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG). //Keeps track of TWR
- FOR PART IN lClamps { //Loop to release launch clamps
- PART:GETMODULE("launchclamp"):DOEVENT("release clamp").
- }. //FOR lClamps release
- SET launchTime TO TIME:SECONDS. //Records liftoff time
- LOCK missionClock TO ROUND((TIME:SECONDS - launchTime), 1). //Sets missionClock to T-0 and starts counting, rounded to tenths of a second
- //~~~~~Staging control~~~~~
- WHEN loxRemaining <= (SBSepLevel / 100) THEN { //Checks to see if side boosters are at sep level
- FOR eng IN LBAll {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine"). //Shutdown right booster engines
- }. //FOR eng
- FOR eng IN RBAll {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine"). //Shutdown left booster engines
- }. //FOR eng
- IF opMode = "2RB" OR opMode = "2R" {
- FOR part IN SBfinHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE). //Extend side booster fins
- }. //FOR finhinge move
- FOR part IN SBAnt {
- SBAnt:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate"). //Activate side booster antennas
- }. //FOR SBant
- }. //IF opMode
- PRINT "T+" + missionClock + " Boosters at sep level. Staging" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- SET BECOtimer to missionClock. //Sets BECOtimer
- WHEN missionClock >= (BECOtimer + 1.5) THEN {
- IF opMode = "Mk2RB" OR opMode = "Mk2R" {
- FOR part IN S2finHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",FALSE). //Stop moving side booster fin hinges
- }. //FOR finhinge stop
- }. //IF
- WHEN missionClock >= (BECOtimer + 2.5) THEN {
- FOR part IN SBDecouplers {
- part:GETMODULE("ModuleDecouple"):DOEVENT("Decouple"). //Decouple side boosters &*&*&*VERIFY&*&*&*
- }. //FOR part
- SET activeStage TO "1".
- WHEN loxRemaining <= (S1SepLevel / 100) THEN { //Checks to see if first stage is at sep level
- FOR eng IN S1All {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine"). //Shutdown S1 engines
- }. //FOR eng shutdown
- IF opMode = "2R" {
- FOR part IN S1finHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE). //Extend fin hinges for reuseable core
- }. //FOR finhinge move
- S1Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate"). //Activate antenna for reuseable core
- }. //IF opMode
- RCS ON.
- SAS ON.
- PRINT "T+" + missionClock + " Stage 1 at sep level, staging" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- SET S1ECOtimer to missionClock. //Marks the time at which S1ECO occurred
- WHEN missionClock >= (S1ECOtimer + 1.5) THEN { //Checks to see if 1.5 seconds has passed since S1ECO
- IF opMode = "2R" {
- FOR part IN S1finHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",FALSE). //Quit extending fin hinges
- }. //FOR finhinge stop
- PRINT "T+" + missionClock + " Fins extended" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //IF opMode
- WHEN missionClock >= (S1ECOtimer + 2.5) THEN { //Checks to see if 2.5 seconds have passed since S1ECO
- interStage:GETMODULE("ModuleDecouple"):DOEVENT("Decouple"). //Separate core and second stage
- PRINT "T+" + missionClock + " Staging confirmed" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- SET activeStage TO 2. //Denotes that stage 2 is now the active stage
- SET loxCap TO S2Tank:RESOURCES[1]:CAPACITY. //Sets loxCap to stage 2 lox capacity
- LOCK loxAmount TO S2Tank:RESOURCES[1]:AMOUNT. //Locks loxAmount to stage 2 lox amount
- WHEN missionClock >= (S1ECOtimer + 7.5) THEN { //Checks to see if 5 seconds have passed since stage sep,
- FOR eng IN S2Alpha {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine"). //Main engine ignition
- }.
- PRINT "T+" + missionClock + " MEI" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- WHEN SHIP:ALTITUDE > 60000 AND missionClock >= (S1ECOtimer + 10.5) THEN { //Fairing sep at 60km or 3 seconds after stage 2 ignition, both conditions need satisfied
- FOR PART IN fairingShell {
- PART:GETMODULE("ProceduralFairingDecoupler"):DOEVENT("Jettison"). //Separate fairings
- }. //FOR loop
- SET fairingSep TO TRUE. //Readout will update to confirm fairing sep status
- S2Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate"). //Activate small omni on second stage
- PRINT "T+" + missionClock + " Fairing separation confirmed" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //WHEN SHIP:ALTITUDE
- }. //WHEN stage2StartTimer
- }. //WHEN BECOtimer decouple
- }. //WHEN BECOtimer finHinges
- }. //WHEN loxRemaining
- }. //WHEN missionClock decouple
- }.//WHEN missionClock fins stop
- }. //WHEN loxRemaining
- //~~~~~Acceleration Control~~~~~
- WHEN TWR > 3.0 AND activeStage = "1B" THEN {
- FOR eng IN LBCharlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter",50). //Drops thrust limiter on LB charlie-group engines to 50%
- }. //FOR eng
- FOR eng IN RBCharlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter",50). //Drops thrust limiter on RB charlie-group engines to 50%
- }. //FOR eng
- FOR eng IN S1Charlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter", 50). //Drops thrust limiter on 1S charlie-group engines to 50%
- }. //FOR eng
- PRINT "T+" + missionClock + " Throttling back charlie-group engines" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- WHEN activeStage = "1" THEN { //Once booster sep is complete, full throttle on S1 charlie-group engines
- FOR eng IN S1Charlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter", 100). //Resets thrust limiter on 1S charlie-group engines to 100%
- }. //FOR eng
- WHEN SHIP:SENSORS:ACC:MAG > 3.0 AND activeStage = "1" THEN {
- FOR eng IN S1Charlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter", 50). //Drops thrust limiter on 1S charlie-group engines to 50%
- }.
- PRINT "T+" + missionClock + " Throttling back charlie-group engines" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //WHEN acc
- }. //WHEN activeStage
- }. //WHEN acc
- //~~~~~Readouts~~~~~
- CLEARSCREEN.
- PRINT "============COYOTE MEDIUM LAUNCH SYSTEM===========" AT(0,0).
- PRINT "ASL: " AT(0,2). //Altitude above sea level readout at 6,2
- PRINT "VEL: " AT(16,2). //Surface or orbital velocity readout at 22,2
- PRINT "CLK: " AT(33,2). //Mission clock readout at 39,2
- PRINT "STG: " AT(0,3). //Current stage readout at 6,3
- PRINT "SFL: " AT(16,3). //Stage fuel level readout at 22,3
- PRINT "FRG: " AT(33,3). //Fairing status readout at 39,3
- PRINT "-------------------EVENT LOG----------------------" AT(0,5).
- PRINT "T-" + ROUND(ABS(BEItime - launchTime),2) + " BEI" AT(0,nextLine). //Time of BEI, will be negative
- SET nextLine TO nextLine + 1.
- PRINT "T+0.0 Liftoff" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- UNTIL SHIP:APOAPSIS >= (targetAlt * 1000) {
- PRINT FLOOR(SHIP:ALTITUDE) + " " AT(6,2).
- IF ALTITUDE <=50000 { //Prints surface velocity below 50km, orbital above
- PRINT ROUND(VELOCITY:SURFACE:MAG,1) + " " AT(22,2).
- } ELSE {
- PRINT ROUND(VELOCITY:ORBIT:MAG,1) + " " AT(22,2).
- }. //IF-ELSE
- PRINT missionClock + " " AT(39,2).
- PRINT activeStage + " " AT(6,3).
- PRINT ROUND((loxRemaining * 100), 1) + "% " AT(22,3).
- IF fairingSep = FALSE { //Prints ATCHD or SPRTD depending on whether the fairings are still on
- PRINT "ATCHD" + " " AT(39,3).
- } ELSE {
- PRINT "SPRTD" + " " AT(39,3).
- }. //IF-ELSE
- WAIT (1 / updateRes). //Update resolution turned into fraction
- }. //UNTIL
- CLEARSCREEN.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- PRINT "Target apoapsis reached. Manual control restored.".
- WAIT 1.
- CLEARSCREEN.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement