Files
ksp-kos-scripts/ascent.ks
T

73 lines
1.7 KiB
Plaintext

// Inital gravity turn
// #include staging
run once staging.
// #include maneuver
run once maneuver.
function doAscentSteering {
parameter heading.
// initial pitch-over
set tarSteer to heading(heading, 90).
lock steering to tarSteer.
until ship:velocity:surface:mag >= 100 {
set tarSteer to heading(heading, 90 - (ship:velocity:surface:mag / 10)).
if defined UPDATE_LOG { UPDATE_LOG(). }
wait 0.
}
lock steering to ship:srfprograde.
print "Locked steering to surface prograde".
}
function createCircularizationNode {
// Re-use existing node if already planned
if hasnode {
print "Existing node found. Skipping creation.".
return nextnode.
}
local rBurn to body:radius + apoapsis.
local vTarget to sqrt(body:mu / rBurn).
local dvEst to vTarget - ship:velocity:orbit:mag.
local nd to node(time:seconds + eta:apoapsis, 0, 0, dvEst).
add nd.
return nd.
}
function basicAscent {
parameter heading is 90, targetAltitude is 80000.
lock throttle to 1.
print "Counting down:".
from {local countdown is 5.} until countdown = 0 step {set countdown to countdown - 1.} do {
print "..." + countdown.
wait 1.
}
// initial stage to takeoff
stage.
// stage everytime thrust drops to zero
basicStaging().
// basic gravity-ish turn
doAscentSteering(heading).
// coast to apoapsis
until ship:apoapsis >= targetAltitude {
if defined UPDATE_LOG { UPDATE_LOG(). }
}
lock steering to ship:prograde.
lock throttle to 0.
// don't do futher calcs until out of the atmosphere or very close to apoapsis
until ship:altitude >= body:atm:height or eta:apoapsis < 60 {
if defined UPDATE_LOG { UPDATE_LOG(). }
}
executeNode(createCircularizationNode()).
print "Circularized".
}