kOS-scripts/launch.ks
Casper V. Kristensen f346414b1a
Restructure.
2018-07-19 21:13:02 +02:00

82 lines
2.1 KiB
Plaintext
Executable file

run once util.
run once vectors.
run once node.
print "====================== LAUNCHING ======================".
parameter orbit_height is 100_000.
parameter pitchover_tilt is 20.
parameter pitchover_altitude is 1000.
parameter pitchover_velocity is 100.
// Auto-stage when the stage has no solid- and liquid fuel left
when (STAGE:SOLIDFUEL + STAGE:LIQUIDFUEL < 1) and STAGE:READY then {
print "STAGING (zero fuel)".
STAGE.
return true. // preserve trigger
}
// Automatically deploy solar panels at 0 atmosphere
when SHIP:DYNAMICPRESSURE = 0 then {
print "Deploying solar panels (zero pressure)".
PANELS ON.
}
// Disable engine gimbal when engine is off
on (not THROTTLE) { // using not to cast to boolean
list engines in engines_list.
for engine in engines_list {
if engine:HASGIMBAL set engine:GIMBAL:LOCK to not THROTTLE.
}
return true. // preserve trigger
}
// VERTICAL CLIMB
print "VERTICAL CLIMB to " + pitchover_altitude + "m or " + pitchover_velocity + "m/s".
SAS OFF.
set NAVMODE to "SURFACE".
lock THROTTLE to 1.0.
lock STEERING to HEADING(90,90).
// Once a certain altitude is reached, a slight turn is made, called the pitchover maneuver
wait until SHIP:ALTITUDE > pitchover_altitude
or SHIP:VELOCITY:SURFACE:MAG > pitchover_velocity.
// PITCHOVER MANEUVER
print "PITCHOVER by " + pitchover_tilt + "°".
lock STEERING to HEADING(90,90-pitchover_tilt).
wait until actual_prograde_pitch() > pitchover_tilt.
// GRAVITY TURN
print "GRAVITY TURN".
lock STEERING to HEADING(90, 90-actual_prograde_pitch()). // follow prograde to get 0 deg angle of attack, but force compass heading 90 (east)
wait until APOAPSIS > orbit_height.
lock THROTTLE TO 0.
unlock STEERING.
// CREATE AND EXECUTE CIRCULARIZATION MANEUVER NODE
create_circularization_node().
execute_node().
// EPILOGUE
// Ensure that the throttle will be 0 when execution stops
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
// Ensure that the player is not locked out of control.
set SHIP:CONTROL:NEUTRALIZE to true.
unlock STEERING.
unlock THROTTLE.
print "====================== LAUNCH SEQUENCE COMPLETE ======================".