Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=====CMLS PRE-LAUNCH CONTROLLER=====
- //~~CMLSlaunch.ks~~
- @LAZYGLOBAL OFF.
- LOCAL scriptVersion TO "v0.3.0".
- //~~~~~Changelog~~~~~ #open
- //0.3.0
- //--Major Improvements--
- // - Migrated all of the pre-launch work to pre-launch
- // script, which will run from the archive. The staging,
- // readout, and control work will be done from the
- // second stage computer.
- // - Created boot script that compiles all CMLS scripts and
- // provides instructions for launch script utilization
- // - Implemented preliminary versions of pitch, roll, and
- // yaw PID controllers.
- // - Integrated boot script that compiles all required
- // scripts and builds the function library
- //--Minor Improvements--
- // - General reorganization of code
- // - All variables now declared prior to use per LAZYGLOBAL
- // - Changed all "ModuleEnginesFX" to "ModuleEngines" to
- // facilitate the uninstallation of HotRockets and
- // CoolRockets
- // - Changed all DOEVENTs to DOACTIONs
- //
- //--TODO: This subversion--
- // - Apply all 0.3 changes to the Mk2 launch script
- // - Test and tune PID gains for all stages
- // - Clean up and integrate RTLS script into 0.3 framework
- // - Test, test, test!!!
- //
- //changelog #close
- //~~~~~Splashscreen~~~~~ #open
- CLEARSCREEN.
- PRINT "==========COYOTE MLS LAUNCH SETUP SCRIPT==========".
- PRINT "----------------------" + scriptVersion + "----------------------".
- WAIT 0.25.
- PRINT "Initializing...".
- //splashscreen #close
- //~~~~~Parameters~~~~~ #open
- PARAMETER targetAlt.
- PARAMETER targetInc.
- PARAMETER launchNode.
- PRINT "Target altitude for initial orbit: " + targetAlt + " kilometers".
- PRINT "Target inclination for initial orbit: " + targetInc + " degrees".
- PRINT "Calculating launch azimuth...".
- GLOBAL launchAzimuth TO LAZcalc(targetAlt, targetInc, launchNode). //Determine launch azimuth
- IF launchNode = "A" {
- PRINT "Launching from the (A)scending node".
- } ELSE IF launchNode = "D" {
- PRINT "Launching from the (D)escending node".
- }.
- //parameters #close
- //~~~~~Variable declaration~~~~~ #open
- LOCAL countdown TO 10. //Length of countdown. Minimum of five seconds required.
- LOCAL CDmessage TO " ". //Holds messages for countdown loop
- GLOBAL nextLine TO 7. //Handles event log printing after liftoff
- GLOBAL fairingSep TO FALSE. //Variable to view fairing separation status; false = still attached
- GLOBAL BECOtimer TO 10000. //Marks BECO time
- GLOBAL S1ECOtimer TO 10000. //Marks S1ECO time
- GLOBAL SBSepLevel TO 0. //Percent of fuel desired for side booster RTLS.
- GLOBAL S1SepLevel TO 0. //Percent of fuel desired for first stage RTLS.
- GLOBAL activeStage TO 0. //Variable to view active stage, Mk2 versions start at 1B (booster)
- GLOBAL updateRes TO 10. //Determines how many refreshes per second for the readout and PID controllers
- SET updateRes TO 1 / updateRes. //Turns updateRes into decimal
- GLOBAL S1LOX TO 0. //Stage 1 liquid oxygen tank
- GLOBAL S2LOX TO 0. //Stage 2 liquid oxygen tank
- GLOBAL LBLOX TO LIST(). //Left booster liquid oxygen tank
- GLOBAL RBLOX TO LIST(). //Right booster liquid oxygen tank
- GLOBAL loxCap TO 0. //Variable to hold capacity of active stage's LOX tank
- GLOBAL loxAmount TO 0. //Variable to hold amount of LOX in active stage's LOX tank
- GLOBAL res TO 0. //Variable to hold resources in FOR loops
- GLOBAL part TO 0. //Variable to hold parts in FOR loops
- GLOBAL eng TO 0. //Variable to hold engines in FOR loops
- GLOBAL rollLock TO 0. //Desired roll
- GLOBAL yawLock TO 0. //Desired yaw
- GLOBAL pitchLock TO 0. //Desired pitch
- //variable declaration #close
- //~~~~~OpMode Management~~~~~ #open
- IF SHIP:PARTSTAGGED("Mk1"):LENGTH > 0 {
- SET opMode TO "1".
- SET activeStage TO "1".
- } ELSE IF SHIP:PARTSTAGGED("Mk1R"):LENGTH > 0 {
- SET opMode TO "1R".
- SET activeStage TO "1".
- SET S1SepLevel TO 15.
- COPY CMLSsburn.ksm TO 2.
- } ELSE IF SHIP:PARTSTAGGED("Mk2"):LENGTH > 0 {
- SET opMode TO "2".
- SET activeStage TO "1B".
- } ELSE IF SHIP:PARTSTAGGED("Mk2RB"):LENGTH > 0 {
- SET opMode TO "2RB".
- SET activeStage TO "1B".
- SET SBSepLevel TO 15.
- COPY CMLSsburn.ksm TO 2.
- COPY CMLSsburn.ksm TO 3.
- } ELSE IF SHIP:PARTSTAGGED("Mk2R"):LENGTH > 0 {
- SET opMode TO "2R".
- SET activeStage TO "1B".
- SET SBSepLevel TO 15.
- SET S1SepLevel TO 20.
- COPY CMLSsburn.ksm TO 2.
- COPY CMLSsburn.ksm TO 3.
- COPY CMLSsburn.ksm TO 4.
- }. //IF
- CMLSeng_Tag(). //Places all tagged engines into approprite lists
- CMLSeng_Shutdown(engAll). //Shuts down all engines for good measure.
- CMLSeng_Limit(engAll, 100). //Sets all thrust limiter at 100 for good measure.
- //opmode management #close
- //~~~~~Parts~~~~~ #open
- //~~Parts common to all variants~~ #open
- SET lClamps TO SHIP:PARTSDUBBED("launchclamp1"). //Launch clamps holding first stage/boosters down
- 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
- SET S2Tank TO SHIP:PARTSTAGGED("S2Tank")[0].
- SET S1Tank TO SHIP:PARTSTAGGED("S1Tank")[0].
- SET S2Ant TO SHIP:PARTSTAGGED("S2Ant")[0]. //Small omnidirectional antenna for second stage communication
- FOR part IN lClamps {
- part:GETMODULE("RefuelingPump"):DOEVENT("Toggle Pump"). //Turn on fuel pump to keep stages topped off
- }. //FOR lClamps pump
- FOR res IN S2Tank:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET S2LOX TO res. //Sets LOX in S1 to S1LOX
- }. //IF res
- }. //FOR res
- FOR res IN S1Tank:RESOURCES {
- IF res:NAME = "LQDOXYGEN" {
- SET S1LOX TO res. //Sets LOX in S2 to S2LOX
- }. //IF res
- }. //FOR res
- //common parts #close
- //~~Parts dependent on variant~~ #open
- IF opMode = "1" OR opMode = "1R" { //Mk1 Variants
- IF opMode = "1R" {
- SET S1Ant TO SHIP:PARTSTAGGED("S1Ant")[0]. //Small omnidirectional antenna for first stage communication
- SET S1finHinges TO SHIP:PARTSTAGGED("S1FinHinge"). //Stage 1 fin hinges
- }. //IF
- SET loxCap TO S1LOX:CAPACITY.
- LOCK loxAmount TO S1LOX:AMOUNT.
- } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" { //Mk2 Variants
- 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
- }. //IF opMode
- 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)
- }. //IF-ELSE opmode parts
- //dependent parts #close
- LOCK loxRemaining TO (loxAmount / (loxCap + 0.01)). //Locks percentage of fuel left in stage +0.01 to avoid divide by zero/NaN
- //parts #close
- //~~~~~Countdown~~~~~ #open
- PRINT "Awaiting launch. Press Action Group 0 to".
- PRINT "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
- CMLSeng_Ignite(engAll). //Activates all first stage and booster engines
- SET CDmessage 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 CDmessage TO " All engines healthy".
- SAS ON.
- } ELSE IF countdown = 1 {
- SET CDmessage TO " Releasing clamps".
- } ELSE {
- SET CDmessage TO " ". //Clears message variable if no event is happening that tick
- }. //IF countdown message
- PRINT "T-" + countdown + CDmessage. //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"):DOACTION("release clamp"). //TEST: DOACTION
- }. //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
- SWITCH TO 1.
- IF opMode = "1" OR opMode = "1R" {
- RUN CMLS1run.
- } ELSE IF opMode = "2" OR opMode = "2RB" OR opMode = "2R" {
- RUN CMLS2run.
- }. //IF-ELSE opMode run
- //countdown #close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement