2021-07-20 01:29:27 +00:00
// runoncepath("lib/sensors").
2021-07-20 00:06:38 +00:00
runoncepath("lib/throttle").
runoncepath("lib/navigation").
2021-07-18 08:07:00 +00:00
2021-07-19 04:54:32 +00:00
parameter APOAPSIS_TARGET is 80000.
parameter GRAVITY_TURN_START is 8000.
parameter GRAVITY_PITCH is 75.
parameter INITIAL_PITCH is 85.
2021-07-20 01:29:27 +00:00
parameter MINIMUM_PITCH is 5.
local ATMO_TWR is 1.6.
2021-07-18 08:07:00 +00:00
2021-07-18 23:32:45 +00:00
// Configure subsystems.
RCS off.
SAS off.
2021-07-18 19:05:26 +00:00
// Countdowns are cute.
print "Initiating automated launch sequence".
from { local x is 5. } until x = 0 step { set x to x - 1. } do {
print "..." + x.
2021-07-19 04:54:32 +00:00
wait 0.5.
2021-07-18 08:07:00 +00:00
}
2021-07-20 00:06:38 +00:00
// Hold throttle to maintain 1.5 TWR.
// We do *not* use a PID Loop here because we can
// calculate the correct value discretely.
2021-07-20 01:29:27 +00:00
lock THROTTLE to ThrottleToTWR(ATMO_TWR).
print "Throttling to maintain a TWR of " + ATMO_TWR.
2021-07-18 08:07:00 +00:00
2021-07-18 19:05:26 +00:00
// Main ascent control.
2021-07-19 04:54:32 +00:00
lock STEERING to heading(90,90,270).
2021-07-18 19:05:26 +00:00
stage.
wait until SHIP:ALTITUDE > 200.
2021-07-18 08:07:00 +00:00
2021-07-20 01:29:27 +00:00
print "Vectoring away from launchpad".
lock STEERING to heading(90, INITIAL_PITCH, 270).
2021-07-18 19:05:26 +00:00
wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
2021-07-19 04:54:32 +00:00
print "Pitching for gravity turn".
2021-07-19 08:46:05 +00:00
// Pitch over...
2021-07-19 04:54:32 +00:00
lock STEERING to heading(90, GRAVITY_PITCH, 270).
2021-07-19 08:46:05 +00:00
// Wait until we have rotated to (approximately) that pitch...
2021-07-19 04:54:32 +00:00
wait until vectorangle(
SHIP:FACING:FOREVECTOR,
STEERINGMANAGER:TARGET:FOREVECTOR)
< 0.5.
2021-07-20 01:29:27 +00:00
2021-07-19 04:54:32 +00:00
// then wait until Prograde catches up.
wait until vectorangle(
SHIP:SRFPROGRADE:FOREVECTOR,
STEERINGMANAGER:TARGET:FOREVECTOR)
< 0.5.
2021-07-20 01:29:27 +00:00
print "Locking to prograde, letting gravity do the hard work.".
lock STEERING to GetAscentVector(MINIMUM_PITCH).
wait until SHIP:ALTITUDE > 32000. // todo: if we have a pressure sensor we can use it to decide when to kick the throttle up instead, neat solution for e.g. Duna and Eve.
2021-07-19 04:54:32 +00:00
2021-07-20 01:29:27 +00:00
lock THROTTLE to 1.0.
wait until SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET.
2021-07-18 08:07:00 +00:00
2021-07-19 08:46:05 +00:00
lock THROTTLE to 0.0.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
2021-07-20 01:29:27 +00:00
wait 0.001. // make sure these control updates get applied
2021-07-19 08:46:05 +00:00
2021-07-20 01:29:27 +00:00
print "Target apoapsis acquired. Creating maneuver node".
2021-07-19 08:46:05 +00:00
AddCircularizationNode().
2021-07-19 08:03:42 +00:00
print "Releasing controls. Circularization maneuver added. Good luck, Kerman!".
2021-07-18 23:32:45 +00:00
unlock THROTTLE.
unlock STEERING.
2021-07-19 04:54:32 +00:00
SAS on.
2021-07-18 23:32:45 +00:00
wait 5.
2021-07-20 01:29:27 +00:00
// todo - automatically execute the node
2021-07-18 23:32:45 +00:00
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").