Created
November 29, 2015 03:54
-
-
Save Tomcc/030abdcbe7a2b8359225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//hellolaunch | |
//First, we'll clear the terminal screen to make it look nice | |
CLEARSCREEN. | |
//schedule an update for the thrust value | |
SET TOTALTHRUST TO 0. | |
when ALT:RADAR > 1000 THEN { | |
LIST ENGINES in ALL_ENGINES. | |
FOR e in ALL_ENGINES { | |
SET TOTALTHRUST TO TOTALTHRUST + e:THRUST * 1000. | |
} | |
PRINT "Total thrust: " + TOTALTHRUST. | |
} | |
SET TARGET_APOAPSIS TO 10000. | |
SET T TO 1.0. | |
SET ROCKET_HEIGHT TO ALT:RADAR. | |
//Next, we'll lock our throttle to 100%. | |
LOCK THROTTLE TO T. // 1.0 is the max, 0.0 is idle. | |
LOCK STEERING TO UP. | |
GEAR OFF. | |
//This is our countdown loop, which cycles from 10 to 0 | |
PRINT "Counting down:". | |
FROM {local countdown is 3.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO { | |
PRINT "..." + countdown. | |
WAIT 1. // pauses the script here for 1 second. | |
} | |
PRINT "LIFTOFF!!!". | |
STAGE. | |
SET LASTTIME TO TIME:SECONDS. | |
UNTIL APOAPSIS > TARGET_APOAPSIS { | |
//every 3 seconds | |
IF TIME:SECONDS > LASTTIME + 3 { | |
SET LASTTIME TO TIME:SECONDS. | |
//going too fast | |
IF SHIP:DYNAMICPRESSURE > 0.26 { | |
SET T TO MAX(0, T - 0.1). | |
PRINT "SLOWDOWN". | |
} | |
IF SHIP:DYNAMICPRESSURE < 0.24 { | |
SET T TO MIN(1, T + 0.1). | |
PRINT "ACCELERATE". | |
} | |
} | |
} | |
SET T TO 0. | |
PRINT "Apoapsis reached at " + APOAPSIS. | |
WAIT UNTIL SHIP:VERTICALSPEED < 0. | |
PRINT "Deploying gear to dispel speed". | |
GEAR ON. | |
//find the current mass ------------------------------ | |
SET M TO 0. | |
FOR p in SHIP:PARTS { | |
IF p:DRYMASS < p:WETMASS { | |
for r in p:RESOURCES { | |
if r:NAME = "LIQUIDFUEL" { | |
SET M TO M + (p:DRYMASS + (p:WETMASS - p:DRYMASS) * (r:AMOUNT / r:CAPACITY)). | |
BREAK. | |
} | |
} | |
} | |
ELSE { | |
SET M TO M + p:DRYMASS. | |
} | |
} | |
SET M TO M*1000. //convert to kg | |
PRINT "CURRENT MASS " + M. | |
///------------------------------------------------- | |
SET DRAG TO 0. | |
WHEN (ALT:RADAR + ROCKET_HEIGHT) <= ((SHIP:AIRSPEED * SHIP:AIRSPEED) / (2 * (((TOTALTHRUST / M) - DRAG) - SHIP:SENSORS:GRAV:MAG))) THEN { | |
PRINT "SUICIDE BURN STARTED". | |
SET T TO 1.0. | |
} | |
SET LASTTIME TO TIME:SECONDS. | |
SET LASTSPEED TO SHIP:VERTICALSPEED. | |
UNTIL SHIP:VERTICALSPEED >= 0 { | |
WAIT 0.5. | |
//extimate drag | |
SET DRAG TO -SHIP:SENSORS:GRAV:MAG - ((SHIP:VERTICALSPEED - LASTSPEED) / (TIME:SECONDS - LASTTIME)). | |
SET LASTTIME TO TIME:SECONDS. | |
SET LASTSPEED TO SHIP:VERTICALSPEED. | |
PRINT "Extimated air drag " + DRAG. | |
} | |
SET T TO 0. | |
PRINT "Suicide burn complete". | |
WAIT 239233. | |
// NOTE that it is vital to not just let the script end right away | |
// here. Once a kOS script just ends, it releases all the controls | |
// back to manual piloting so that you can fly the ship by hand again. | |
// If the program just ended here, then that would cause the throttle | |
// to turn back off again right away and nothing would happen. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment