Files
kOS/poweredLanding.ks
Amatsugu b90b0157e4 finalized raden launch
wip landing script
2025-11-20 01:29:40 -05:00

94 lines
2.0 KiB
Plaintext

run "library/lib_vessel_utils".
run "library/lib_location_constants".
run tests.
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
function TestSetup{
print "Setting up test".
lock throttle to 100.
wait until apoapsis > 5000.
lock steering to up.
lock throttle to 0.
unlock throttle.
}
function LandAtPad{
print "Starting Landing".
gear on.
set pad to location_constants:kerbin:launchpad:position.
lock dist to pad.
lock steering to srfRetrograde.
rcs on.
set landingThrottle to 0.
lock throttle to landingThrottle.
set hoverPid to PIDLoop(5, 0.1, 30, 0, 1).
set tgtAlt to 100.
set hoverPid:setpoint to tgtAlt.
set landed to false.
when abs(verticalSpeed) < 10 or verticalSpeed > 1 then{
lock steering to up.
preserve.
}
when verticalSpeed < -10 then{
lock steering to srfRetrograde.
preserve.
}
until landed {
set landingThrottle to hoverPid:update(time:seconds, alt:radar).
// print "offset " + dist.
wait 0.001.
}
}
function Descent{
print "Coasting to apoapsis.".
rcs on.
lock steering to up.
set warp to 1.
wait until verticalSpeed < -100.
set warp to 0.
print "Falling...".
lock steering to srfRetrograde.
brakes on.
local lock vertSpeed to verticalSpeed.
local lock isp to GetIsp().
local lock localGravity to GetLocalGravity(altitude).
local lock burnDuration to CalculateSuicideBurnDuration(isp).
local lock imactTime to CalculateTimeToImpact(abs(vertSpeed), alt:radar, localGravity).
local lock burnAlt to CalculateSuicideBurnAltitude(vertSpeed, localGravity).
local lock timeToBurn to imactTime - burnDuration.
until timeToBurn < 0.5 {
// print "time: " + round(timeToBurn) + " len: " + burnDuration + " impact: " + imactTime + " alt: " + burnAlt.
}
wait until timeToBurn < 0.5.
until abs(verticalSpeed) < 50{
lock throttle to 1.
}
SET V0 TO GETVOICE(0).
V0:PLAY( NOTE(400, 0.5) ).
lock throttle to 0.
}
print "Launch to start.".
WaitForEngineStart().
TestSetup().
Descent().
LandAtPad().