117 lines
2.3 KiB
Plaintext
117 lines
2.3 KiB
Plaintext
run "library/lib_vessel_utils".
|
|
run "library/lib_math".
|
|
run "library/lib_location_constants".
|
|
run "defaults".
|
|
|
|
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
|
|
|
|
|
function TestSetup{
|
|
parameter tgt is 5000.
|
|
if altitude > 100 {
|
|
return.
|
|
}
|
|
print "Setting up test".
|
|
lock throttle to 0.5.
|
|
lock steering to heading(90, 89, 0).
|
|
gear off.
|
|
wait until apoapsis > tgt.
|
|
lock steering to up.
|
|
lock throttle to 0.
|
|
unlock throttle.
|
|
}
|
|
|
|
function Landing{
|
|
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.
|
|
set steerPitch to 0.0.
|
|
set steerYaw to 0.0.
|
|
lock throttle to landingThrottle.
|
|
set tgtAlt to 80.
|
|
|
|
|
|
set pitchPid to PIDLoop(0.55, 0.06, 0.3, -1, 1).
|
|
set yawPid to PIDLoop(0.55, 0.06, 0.3, -1, 1).
|
|
set hoverPid to PIDLoop(0.1, 0.06, 0.01, 0, 1).
|
|
|
|
set hoverPid:setpoint to -1.
|
|
set pitchPid:setpoint to 0.
|
|
set yawPid:setpoint to 0.
|
|
|
|
set landed to false.
|
|
|
|
|
|
|
|
when verticalSpeed > -10 then{
|
|
lock steering to up.
|
|
preserve.
|
|
}
|
|
|
|
when verticalSpeed < -10 then{
|
|
lock steering to srfRetrograde.
|
|
preserve.
|
|
}
|
|
|
|
|
|
until landed {
|
|
set landingThrottle to hoverPid:update(time:seconds, verticalSpeed).
|
|
set hoverPid:setpoint to Map(alt:radar, 0, 100, -0.5, -30).
|
|
wait 0.001.
|
|
}
|
|
print "Landed".
|
|
lock throttle to 0.
|
|
}
|
|
|
|
function WaitFalling{
|
|
parameter targetSpeed is 100.
|
|
sas off.
|
|
wait until altitude < 10000.
|
|
print "Coasting to apoapsis.".
|
|
rcs on.
|
|
lock steering to up.
|
|
set warp to 1.
|
|
wait until verticalSpeed < -targetSpeed.
|
|
set warp to 0.
|
|
print "Falling...".
|
|
lock steering to srfRetrograde.
|
|
brakes on.
|
|
}
|
|
|
|
|
|
function Descent {
|
|
|
|
local lock curAlt to alt:radar.
|
|
local lock vertSpeed to verticalSpeed.
|
|
local lock localGravity to GetLocalGravity(altitude).
|
|
local lock drag to GetDragDir(localGravity, ship:up:vector).
|
|
local lock burnDist to CalculateSuicideBurnAltitude(vertSpeed, localGravity, 100, drag).
|
|
|
|
wait until burnDist >= curAlt.
|
|
print "Starting Burn".
|
|
print burnDist.
|
|
gear on.
|
|
|
|
until abs(verticalSpeed) < 30{
|
|
lock throttle to 1.
|
|
}
|
|
lock throttle to 0.
|
|
print "Final".
|
|
print curAlt.
|
|
|
|
}
|
|
|
|
|
|
print "Launch to start.".
|
|
WaitForEngineStart().
|
|
TestSetup(10000).
|
|
WaitFalling(100).
|
|
Descent().
|
|
Landing().
|
|
|