Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==Coyote Medium LS Launch script 1 and 1R==
- 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 S1ECOtimer TO 10000. //Marks S1ECO time
- SET S1SepLevel TO 0. //Percent of fuel desired for first stage RTLS.
- SET activeStage TO "1". //Variable to view active stage
- SET updateRes TO 10. //Determines how many refreshes per second for the readout script
- //~~~~~Script management and more variables~~~~~
- IF SHIP:PARTSTAGGED("Mk1"):LENGTH > 0 {
- SET opMode TO "1".
- } ELSE IF SHIP:PARTSTAGGED("Mk1R"):LENGTH > 0 {
- SET opMode TO "1R".
- COPY CMLSsburn.ksm FROM 0.
- COPY CMLSsburn.ksm TO 2.
- DELETE CMLSsburn.ksm FROM 1.
- COPY CMLSeng.ksm FROM 0.
- COPY CMLSeng.ksm TO 2.
- DELETE CMLSeng.ksm FROM 1.
- SET S1SepLevel TO 15.
- }. //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 = "1R" {
- SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0]. //Small omnidirectional antenna for first stage communication
- SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge").
- }. //IF opMode antenna
- 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].
- SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0].
- FOR res IN S1Tank:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET S1LOX TO res.
- SET loxCap TO S1LOX:CAPACITY.
- }. //IF res
- }. //FOR res
- LOCK loxAmount TO S1LOX:AMOUNT.
- 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 {
- 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.
- } 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 " ".
- }. //IF countdown message
- PRINT "T-" + countdown + message.
- 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 <= (S1SepLevel / 100) THEN { //Checks to see if first stage is at sep level, shutdown engines and extend fins if true
- FOR eng IN S1All {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Shutdown Engine").
- }. //FOR eng shutdown
- IF opMode = "1R" {
- FOR part IN S1finHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",TRUE).
- }. //FOR finhinge move
- S1Ant:GETMODULE("ModuleRTAntenna"):DOEVENT("Activate").
- }. //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, quit extending fins if true
- IF opMode = "1R" {
- FOR part IN S1finHinges {
- PART:GETMODULE("MuMechToggle"):DOACTION("move -",FALSE).
- }. //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, stage sep if true
- interStage:GETMODULE("ModuleDecouple"):DOEVENT("Decouple").
- 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.
- LOCK loxAmount TO S2Tank:RESOURCES[1]:AMOUNT.
- WHEN missionClock >= (S1ECOtimer + 7.5) THEN { //Checks to see if 5 seconds have passed since stage sep, MEI if true
- FOR eng IN S2Alpha {
- eng:GETMODULE("ModuleEnginesFX"):DOEVENT("Activate Engine").
- }.
- 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").
- }. //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
- //~~~~~Acceleration Control~~~~~
- WHEN TWR > 3.0 AND activeStage = "1" THEN {
- FOR eng IN S1Charlie {
- eng:GETMODULE("ModuleEnginesFX"):SETFIELD("Thrust Limiter",50).
- }. //FOR eng
- PRINT "T+" + missionClock + " Throttling back charlie-group engines" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //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