172 lines
4.9 KiB
Plaintext
172 lines
4.9 KiB
Plaintext
@lazyglobal off.
|
|
|
|
runoncepath("0:/lib/common.ks").
|
|
|
|
global centaur is lex(
|
|
"orbit", do_orbit@,
|
|
"power_down", power_down@,
|
|
"power_up", power_up@,
|
|
"low_power", low_power@,
|
|
"separate", separate@,
|
|
"transfer_burn", transfer_burn@,
|
|
"burn_time", centaur_burn_time@,
|
|
"capture_burn", capture_burn@
|
|
).
|
|
|
|
local function do_orbit {
|
|
parameter hdg, target_ecc is 0.002, max_vel_delta is 0.1.
|
|
|
|
print "Centaur startup".
|
|
local dv is circularization_dv().
|
|
local circularization_time is centaur_burn_time(dv).
|
|
local half_circularization_time is centaur_burn_time(dv / 2).
|
|
print "Circularization is " + dv + "m/s over " + circularization_time + "s".
|
|
print "Will burn " + half_circularization_time + "s before AP".
|
|
|
|
local ignition_time is half_circularization_time.
|
|
local ullage_time is ignition_time + 3.
|
|
local steering_time is ullage_time + 20.
|
|
|
|
print "Warping to burn".
|
|
set warpmode to "physics".
|
|
set warp to 3.
|
|
wait until eta:apoapsis < steering_time.
|
|
set warp to 0.
|
|
wait 1.
|
|
wait until kuniverse:timewarp:issettled.
|
|
|
|
print "RCS On. Locking heading".
|
|
rcs on.
|
|
local target is heading(hdg, ship:obt:trueanomaly - 180, -hdg).
|
|
lock steering to target.
|
|
wait until eta:apoapsis < ullage_time.
|
|
|
|
print "Throttle up".
|
|
lock throttle to 1.0.
|
|
wait until eta:apoapsis < ignition_time.
|
|
stage.
|
|
print "GO GO GO".
|
|
wait until ship:velocity:orbit:mag > circular_vel() and ship:obt:periapsis > 140000.
|
|
lock throttle to 0.0.
|
|
lock steering to lookdirup(ship:prograde:forevector, ship:up:forevector).
|
|
until false {
|
|
local threshold is 0.1.
|
|
local p is threshold / max_vel_delta.
|
|
local dv is circular_vel() - ship:velocity:orbit:mag.
|
|
local vert_vel is ship:verticalspeed * ship:up:forevector.
|
|
local vert_vel_d is 0.0 - vert_vel:mag.
|
|
local horz_vel_d is circular_vel() - (ship:velocity:orbit - vert_vel):mag.
|
|
local horz_factor is horz_vel_d * p.
|
|
local vert_factor is vert_vel_d * p.
|
|
if ship:obt:eccentricity < target_ecc or (abs(horz_factor) < threshold and abs(vert_factor) < threshold) {
|
|
set ship:control:fore to 0.
|
|
set ship:control:top to 0.
|
|
break.
|
|
}
|
|
set ship:control:fore to horz_factor.
|
|
set ship:control:top to vert_factor.
|
|
wait 0.
|
|
}
|
|
rcs off.
|
|
unlock steering.
|
|
wait 0.
|
|
print "Centaur done".
|
|
}
|
|
|
|
local function power_down {
|
|
local avionics is ship:partsdubbed("centaur-avionics")[0].
|
|
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
|
|
avi_mod:doaction("shutdown avionics", true).
|
|
}
|
|
|
|
local function power_up {
|
|
local avionics is ship:partsdubbed("centaur-avionics")[0].
|
|
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
|
|
avi_mod:doaction("activate avionics", true).
|
|
}
|
|
|
|
local function low_power {
|
|
local avionics is ship:partsdubbed("centaur-avionics")[0].
|
|
local power is avionics:resources[0].
|
|
return power:amount / power:capacity < 0.1.
|
|
}
|
|
|
|
local function separate {
|
|
rcs on.
|
|
lock steering to prograde.
|
|
lock throttle to 1.0.
|
|
wait 5.
|
|
lock throttle to 0.0.
|
|
unlock steering.
|
|
rcs off.
|
|
}
|
|
|
|
local function transfer_burn {
|
|
parameter target_ap.
|
|
|
|
// Shutdown engine for ullage
|
|
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
|
|
engine:shutdown().
|
|
lock throttle to 1.0.
|
|
wait 3.
|
|
// Engine on
|
|
engine:activate().
|
|
wait until ship:obt:apoapsis > target_ap.
|
|
lock throttle to 0.0.
|
|
wait 0.
|
|
}
|
|
|
|
local function centaur_burn_time {
|
|
parameter dv.
|
|
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
|
|
return burn_time(dv, engine).
|
|
}
|
|
|
|
local function capture_burn {
|
|
parameter threshold is 250_000.
|
|
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
|
|
engine:shutdown().
|
|
local initial_pe is ship:obt:periapsis.
|
|
wait 1.
|
|
warpto(eta:periapsis + time:seconds - 30).
|
|
wait 1.
|
|
wait until kuniverse:timewarp:warp = 0.
|
|
wait until kuniverse:timewarp:issettled.
|
|
power_up().
|
|
rcs on.
|
|
lock steering to ship:retrograde.
|
|
wait 1.
|
|
wait until steering_locked().
|
|
lock throttle to 1.
|
|
wait 3.
|
|
engine:activate().
|
|
|
|
if initial_pe > threshold {
|
|
wait until ship:obt:periapsis < (threshold/2).
|
|
lock throttle to 0.
|
|
engine:shutdown().
|
|
power_down().
|
|
unlock steering.
|
|
wait 1.
|
|
warpto(eta:periapsis + time:seconds - 30).
|
|
wait 1.
|
|
wait until kuniverse:timewarp:warp = 0.
|
|
wait until kuniverse:timewarp:issettled.
|
|
wait 1.
|
|
power_up().
|
|
lock steering to ship:retrograde.
|
|
wait 1.
|
|
wait until steering_locked().
|
|
lock throttle to 1.
|
|
wait 3.
|
|
engine:activate().
|
|
wait until ship:obt:apoapsis < (threshold*2).
|
|
} else {
|
|
wait until ship:obt:eccentricity < 1 and ship:obt:apoapsis < threshold*2.
|
|
}
|
|
|
|
engine:shutdown().
|
|
lock throttle to 0.
|
|
power_down().
|
|
wait 1.
|
|
} |