Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Atlas Launch Controller
- @LAZYGLOBAL OFF.
- LOCAL scriptVersion TO "v0.1".
- //=========================================================
- //Script Initialization #open
- CLEARSCREEN.
- SET TERMINAL:WIDTH TO 50.
- SET TERMINAL:HEIGHT TO 25.
- PRINT "==============ATLAS LAUNCH CONTROLLER=============".
- PRINT "----------------Script Version " + scriptVersion + "---------------".
- PRINT "Initializing...".
- DECLARE PARAMETER
- targetAlt, //Target altitude of final circular orbit
- targetInc. //Target inclination of final circular orbit; negative for southerly launch
- SWITCH TO 0.
- RUN LIB_LAZcalc.ks. //Launch azimuth calculator
- RUN LIB_PID.ks. //Generic PID controller
- RUN LIB_navball.ks. //Navball reading translator
- SWITCH TO 1.
- //initialization #close
- //=========================================================
- //Variable Declaration #open
- LOCAL opMode TO -1. //Pre-launch start value
- LOCAL typeFairing TO "3". //Fairing diameter
- LOCAL typeBooster TO "0". //Number of SRBs
- LOCAL typeEngines TO "1". //Number of upper stage engines
- LOCAL vesselType TO typeFairing + typeBooster + typeEngines. //Puts it all together
- LOCAL launchAzimuth TO LAZcalc(targetAlt, targetInc). //Determines launch azimuth
- LOCAL controlReady TO FALSE. //Whether to implement PID controller
- LOCAL controlMode TO "Modified". //Modified has roll as compass heading for initial upwards launch; Standard has roll as normal
- LOCAL readoutReady TO FALSE. //Whether to display readouts
- LOCAL logReady TO FALSE. //Whether to log flight data
- LOCAL countdown TO 10. //Countdown start value
- LOCAL countdownMessage TO " ". //Countdown message holder
- LOCAL activeStage TO 1. //Stores active stage
- LOCAL missionClock TO -1. //Stores seconds since launch
- LOCAL launchTime TO -1. //Stores time of launch clamp release
- LOCAL pitchInit TO PID_init(0.05,0.02,0,-1,1). //Initial values for first stage flight
- LOCAL rollInit TO PID_init(0.05,0.02,0,-1,1). //Initial values for first stage flight
- LOCAL yawInit TO PID_init(0.05,0.02,0,-1,1). //Initial values for first stage flight
- LOCAL pitchDesired TO 0. //Desired pitch value (ship orientation)
- LOCAL rollDesired TO 0. //Desired roll value (ship orientation)
- LOCAL yawDesired TO 0. //Desired yaw value (ship orientation)
- LOCAL pitchCurrent TO pitch_for(SHIP). //Starts at 90 on launchpad
- LOCAL rollCurrent TO compass_for(SHIP). //Starts as compass heading of top of ship
- LOCAL yawCurrent TO 0. //Starts as 0
- LOCAL throttInit TO PID_init(0.05,0.02,0,-1,1). //Initial values for first stage flight
- LOCAL throttDesired TO 0. //Desired throttle value
- LOCAL TWR TO 0.
- //declaration #close
- //=========================================================
- //Parts declaration #open
- LOCAL LOXTanks TO LIST(SHIP:PARTSTAGGED("S1Tank"), SHIP:PARTSTAGGED("S2Tank")). //Array holding both stage's LOX tanks
- LOCAL stageOxidizerCapacity TO LIST(LOXTanks[0]:LQDOXYGEN:CAPACITY, LOXTanks[1]:LQDOXYGEN:CAPACITY). //Array holding capacity of both stage's LOX tanks
- LOCAL S2RCSTank TO SHIP:PARTSTAGGED("S2RCSTank"). //Stage 2 RCS tank
- LOCAL S2RCSCapacity TO S2RCSTank:A50:CAPACITY. //Stage 2 RCS tank capacity
- //parts declaration #close
- //=========================================================
- //Locks #open
- LOCK missionClock TO launchTime - TIME:SECONDS. //Keeps track of time since launch clamp release
- LOCK TWR TO SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG). //Keeps track of TWR
- LOCK stageOxidizerAmount TO LOXTanks[activeStage + 1]:LQDOXYGEN:AMOUNT + 0.001. //Keeps track of LOX amount in active stage
- LOCK stageOxidizerLevel TO (stageOxidizerAmount / stageOxidizerCapacity) * 100. //Keeps track of percent LOX remaining in active stage
- LOCK S2RCSAmount TO S2RCSTank:A50:AMOUNT + 0.001. //Keeps track of Stage 2 RCS amount
- LOCK S2RCSLevel TO (S2RCSAmount / S2RCSCapacity) * 100. //Keeps track of percent Stage 2 RCS remaining
- LOCK SHIP:CONTROL:PITCH TO pitchControl. //Variable to set pitch
- LOCK SHIP:CONTROL:ROLL TO rollControl. //Variable to set roll
- LOCK SHIP:CONTROL:YAW TO yawControl. //Variable to set yaw
- LOCK THROTTLE TO throttControl. //Variable to set throttle
- //locks #close
- //=========================================================
- //Main Loop #open
- UNTIL opMode = 0 {
- IF opMode = -1 { //Pre-countdown
- PRINT "Vehicle type: " + vesselType.
- PRINT "Desired orbit altitude: " + targetAlt.
- PRINT "Desired orbit inclination: " + targetInc.
- PRINT "Launch Azimuth: " + ROUND(launchAzimuth).
- IF logReady = TRUE {
- LOG vesselType TO atlasLog_params.txt.
- LOG targetAlt TO atlasLog_params.txt.
- LOG targetInc TO atlasLog_params.txt.
- LOG launchAzimuth TO atlasLog_params.txt.
- }. //IF logReady
- PRINT "**Press AG10 to initiate countdown**".
- AG10 OFF. //Ensures AG10 is off to prevent immediate countdown initiation
- SET opMode TO 100.
- } ELSE IF opMode = 100 AND AG10 = TRUE { //Countdown
- IF countdown = 5 {
- SET throttControl TO 1.
- } ELSE IF countdown = 3 {
- STAGE. //Main Engines
- SET countdownMessage TO "Main Engine Ignition".
- } ELSE IF countdown = 1 {
- SET countdownMessage TO "Releasing Launch Clamps".
- }. //IF
- PRINT "T-" + countdown + " " + countdownMessage.
- SET countdownMessage TO " ".
- WAIT 1.
- IF countdown = 0 {
- STAGE. //Ignite SRBs and release clamps
- CLEARSCREEN.
- PRINT "==============ATLAS LAUNCH CONTROLLER=============" AT(0,0).
- PRINT "ASL: " AT(0,1). PRINT "VEL: " AT(16,1). PRINT "CLK: " AT(33,1). //Readouts at 5, 21, 38
- PRINT "STG: " AT(0,2). PRINT "SFL: " AT(16,2). PRINT "RCS: " AT(33,2). //Readouts at 5, 21, 38
- PRINT "---------------------EVENT LOG--------------------" AT(0,3).
- SET controlReady TO TRUE.
- SET readoutReady TO TRUE.
- SET opMode TO 200.
- }. //IF
- } ELSE IF opMode = 200 { //Initial climb and roll to launch azimuth
- SET pitchControl TO 90. //Straight up
- SET rollControl TO launchAzimuth. //Roll to heads-up as launch azimuth; modified controlMode requried
- SET yawControl TO 0.
- }. //IF
- IF controlReady = TRUE {
- IF controlMode = "Standard" { //For regular flying
- SET currentPitch TO pitch_for(SHIP). //Positive is above horizon
- SET currentRoll TO roll_for(SHIP). //Regular roll value; needs trickery for heads-down piloting
- SET currentYaw TO compass_for(SHIP). //Compass heading
- } ELSE IF controlMode = "Modified" { //For initial vertical flight
- //TODO: Figure out how to avoid gimbal lock
- }.
- }. //IF controlReady
- IF readoutReady = TRUE {
- PRINT ROUND(SHIP:ALTITUDE) AT(5,1).
- IF SHIP:ALTITUDE > 50000 {
- PRINT ROUND(VELOCITY:ORBIT:MAG, 1) AT(21,1).
- } ELSE {
- PRINT ROUND(VELOCITY:SURFACE:MAG, 1) AT(21,1).
- }.
- PRINT ROUND(missionClock, 1) AT(38,1).
- PRINT activeStage AT(5,2).
- PRINT ROUND(stageOxidizerLevel, 1) AT(21,2).
- PRINT ROUND(S2RCSLevel, 1) AT(38,2).
- }.//IF readoutReady
- IF logReady = TRUE {
- LOG missionClock TO atlasLog_Clock.txt.
- LOG TWR TO atlasLog_TWR.txt.
- LOG SHIP:ALTITUDE TO atlasLog_alt.txt.
- LOG VELOCITY:ORBIT:MAG TO atlasLog_orbitVel.txt.
- LOG VELOCITY:SURFACE:MAG TO atlasLog_surfVel.txt.
- LOG stageOxidizerLevel TO atlasLog_stageLOXlevel.txt.
- LOG S2RCSLevel TO atlasLog_S2RCSlevel.txt.
- LOG pitchControl TO atlasLog_pitchControl.txt.
- LOG rollControl TO atlasLog_rollControl.txt.
- LOG yawControl TO atlasLog_yawControl.txt.
- LOG pitchDesired TO atlasLog_pitchDesired.txt.
- LOG rollDesired TO atlasLog_rollDesired.txt.
- LOG yawDesired TO atlasLog_yawDesired.txt.
- LOG throttDesired TO atlasLog_throttDesired.txt.
- LOG pitchCurrent TO atlasLog_pitchCurrent.txt.
- LOG rollCurrent TO atlasLog_rollCurrent.txt.
- LOG yawCurrent TO atlasLog_yawCurrent.txt.
- }. //IF logReady
- }. //UNTIL
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- UNLOCK THROTTLE.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement