finally working landing script
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
run "library/lib_vessel_utils".
|
||||
run "library/lib_math".
|
||||
run "library/lib_location_constants".
|
||||
run tests.
|
||||
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 100.
|
||||
wait until apoapsis > 5000.
|
||||
lock steering to heading(90, 89).
|
||||
gear off.
|
||||
wait until apoapsis > tgt.
|
||||
lock steering to up.
|
||||
lock throttle to 0.
|
||||
unlock throttle.
|
||||
unlock steering.
|
||||
}
|
||||
|
||||
|
||||
function LandAtPad{
|
||||
function Landing{
|
||||
print "Starting Landing".
|
||||
gear on.
|
||||
set pad to location_constants:kerbin:launchpad:position.
|
||||
@@ -23,14 +31,25 @@ function LandAtPad{
|
||||
rcs on.
|
||||
|
||||
set landingThrottle to 0.
|
||||
set steerPitch to 0.0.
|
||||
set steerYaw to 0.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 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 abs(verticalSpeed) < 10 or verticalSpeed > 1 then{
|
||||
|
||||
|
||||
when verticalSpeed > -10 then{
|
||||
lock steering to up.
|
||||
preserve.
|
||||
}
|
||||
@@ -40,54 +59,57 @@ function LandAtPad{
|
||||
preserve.
|
||||
}
|
||||
|
||||
until landed {
|
||||
set landingThrottle to hoverPid:update(time:seconds, alt:radar).
|
||||
|
||||
// print "offset " + dist.
|
||||
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 Descent{
|
||||
function WaitFalling{
|
||||
parameter targetSpeed is 100.
|
||||
print "Coasting to apoapsis.".
|
||||
rcs on.
|
||||
lock steering to up.
|
||||
set warp to 1.
|
||||
wait until verticalSpeed < -100.
|
||||
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 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.
|
||||
}
|
||||
local lock drag to GetDragDir(localGravity, ship:up:vector).
|
||||
local lock burnDist to CalculateSuicideBurnAltitude(vertSpeed, localGravity, 80, drag).
|
||||
|
||||
wait until timeToBurn < 0.5.
|
||||
wait until burnDist >= curAlt.
|
||||
print "Starting Burn".
|
||||
print burnDist.
|
||||
gear on.
|
||||
|
||||
|
||||
until abs(verticalSpeed) < 50{
|
||||
until abs(verticalSpeed) < 30{
|
||||
lock throttle to 1.
|
||||
}
|
||||
|
||||
|
||||
SET V0 TO GETVOICE(0).
|
||||
V0:PLAY( NOTE(400, 0.5) ).
|
||||
lock throttle to 0.
|
||||
print "Final".
|
||||
print curAlt.
|
||||
|
||||
}
|
||||
|
||||
|
||||
print "Launch to start.".
|
||||
WaitForEngineStart().
|
||||
TestSetup().
|
||||
TestSetup(5000).
|
||||
WaitFalling(100).
|
||||
Descent().
|
||||
LandAtPad().
|
||||
Landing().
|
||||
|
||||
|
||||
Reference in New Issue
Block a user