Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=====CMLS Mk1/Mk1R LAUNCH CONTROL SCRIPT=====
- //~~CMLS1run.ks~~
- @LAZYGLOBAL OFF.
- LOCAL scriptVersion TO "v0.3.0".
- //Changelog located in CMLSlaunch script
- //~~~~~Staging Control~~~~~ #open
- WHEN loxRemaining <= (SBSepLevel / 100) THEN { //Checks to see if side boosters are at sep level
- CMLSeng_Shutdown(LBAll).
- CMLSeng_Shutdown(RBAll).
- 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, shutdown engines and extend fins if true
- CMLSeng_Shutdown(S1All).
- 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.
- 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
- CMLSeng_Ignite(S2Alpha). //Ignite stage 2 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
- }. //WHEN missionClock decouple
- }.//WHEN missionClock fins stop
- }. //WHEN loxRemaining
- //staging #close
- //~~~~~Directional Control~~~~~ #open
- SET pitchPID TO PID_Init(0.05, 0, 0). //TEST: Pitch PID gains
- SET rollPID TO PID_Init(0.05, 0, 0). //TEST: Roll PID gains
- SET yawPID TO PID_Init(0.02, 0, 0). //TEST: Yaw PID gains
- WHEN VELOCITY:SURFACE:MAG > 10 { //Once we get going
- SAS OFF.
- SET pitchLock TO 88. //Pulls the ship slightly off of directly up to have the roll make sense
- SET rollLock TO 180. //Rolls heads down; will remain so throughout launch
- SET yawLock TO launchAzimuth. //Yaws towards the launch azimuth
- WHEN ABS(currentYaw - launchAzimuth) < 5 { //Once yaw maneuver is nearly complete
- SET pitchLock TO 80. //Pitch kick; pulls ten degrees down to get the gravity turn started
- WHEN VELOCITY:SURFACE:MAG > 120 {
- LOCK pitchLock TO SHIP:SRFPROGRADE:PITCH. //Locks pitch to surface prograde
- WHEN activeStage = "1" { //Once the boosters have fallen off
- //TODO: Implement updated PID gains for booster-less flight
- WHEN activeStage = "2" { //Once staging is confirmed
- LOCK pitchLock TO SHIP:PROGRADE:PITCH. //Locks pitch to orbit prograde
- LOCK yawLock TO SHIP:SRFPROGRADE:YAW. //Locks yaw to surface prograde; should roughly hold sidereal launch azimuth
- //TODO: Implement updated PID gains for second stage
- WHEN ETA:APOAPSIS < 5 {
- LOCK pitchLock TO SHIP:VERTICALSPEED. //TEST: See if this maintains vertical speed
- }. //WHEN eta:apoapsis
- }. //WHEN activeStage 2
- }. //WHEN activeStage 1
- }. //WHEN surfVel
- }. //WHEN surfVel
- }. //WHEN surfVel
- //directional control #close
- //~~~~~Acceleration Control~~~~~ #open
- WHEN TWR > 3.0 AND activeStage = "1" THEN {
- FOR eng IN S1Charlie {
- eng:GETMODULE("ModuleEngines"):SETFIELD("Thrust Limiter",50).
- }. //FOR eng
- PRINT "T+" + missionClock + " Throttling back charlie-group engines" AT(0,nextLine).
- SET nextLine TO nextLine + 1.
- }. //WHEN acc
- //acceleration control #close
- //~~~~~Readout Header~~~~~ #open
- CLEARSCREEN.
- PRINT "============COYOTE MEDIUM LAUNCH SYSTEM===========" AT(0,2).
- PRINT "ASL: " AT(0,3). //Altitude above sea level readout at 6,3
- PRINT "VEL: " AT(16,3). //Surface or orbital velocity readout at 22,3
- PRINT "CLK: " AT(33,3). //Mission clock readout at 39,3
- PRINT "STG: " AT(0,4). //Current stage readout at 6,4
- PRINT "SFL: " AT(16,4). //Stage fuel level readout at 22,4
- PRINT "FRG: " AT(33,4). //Fairing status readout at 39,4
- 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.
- //readout header #close
- //~~~~~Run Loop~~~~~ #open
- UNTIL SHIP:APOAPSIS >= (targetAlt * 1000) {
- //~~Directional Control~~ #open
- //Pitch Control
- SET currentPitch TO 90 - VECTORANGLE(UP:VECTOR, SHIP:FACING:FOREVECTOR).
- SET SHIP:CONTROL:PITCH TO PID_Seek(pitchPID, pitchLock, currentPitch).
- //Roll Control
- SET currentroll TO VECTORANGLE(UP:VECTOR, SHIP:FACING:STARVECTOR).
- SET SHIP:CONTROL:ROLL TO PID_Seek(rollPID, rollLock, currentRoll).
- //Yaw Control
- SET rawyaw TO (-1 * SHIP:BEARING).
- IF rawyaw < 0 {
- SET currentyaw TO (rawyaw + 360).
- } ELSE {
- SET currentyaw TO rawyaw.
- }.
- SET SHIP:CONTROL:YAW TO PID_Seek(yawPID, yawLock, currentYaw).
- //directional control #close
- //~~Readouts~~ #open
- //Mission info
- PRINT FLOOR(SHIP:ALTITUDE) + " " AT(6,3).
- IF ALTITUDE <=50000 { //Prints surface velocity below 50km, orbital above
- PRINT ROUND(VELOCITY:SURFACE:MAG,1) + " " AT(22,3).
- } ELSE {
- PRINT ROUND(VELOCITY:ORBIT:MAG,1) + " " AT(22,3).
- }. //IF-ELSE
- PRINT missionClock + " " AT(39,3).
- //Systems info
- PRINT activeStage + " " AT(6,4).
- PRINT ROUND((loxRemaining * 100), 1) + "% " AT(22,4).
- IF fairingSep = FALSE { //Prints ATCHD or SPRTD depending on whether the fairings are still on
- PRINT "ATCHD" + " " AT(39,4).
- } ELSE {
- PRINT "SPRTD" + " " AT(39,4).
- }. //IF-ELSE
- //readouts #close
- WAIT updateRes.
- }. //UNTIL
- //run loop #close
- //~~~~~Exit instructions~~~~~ #open
- CLEARSCREEN.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- PRINT "Target apoapsis reached. Manual control restored.".
- WAIT 1.
- CLEARSCREEN.
- //exit #close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement