finalized raden launch
wip landing script
This commit is contained in:
@@ -1,58 +1,93 @@
|
||||
run "library/lib_vessel_utils".
|
||||
run "library/lib_location_constants".
|
||||
run tests.
|
||||
|
||||
//-126
|
||||
function DeOrbit{
|
||||
parameter burnLng, deltaV.
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||
|
||||
lock pos to SHIP:geoposition.
|
||||
function TestSetup{
|
||||
print "Setting up test".
|
||||
lock throttle to 100.
|
||||
wait until apoapsis > 5000.
|
||||
lock steering to up.
|
||||
lock throttle to 0.
|
||||
unlock throttle.
|
||||
}
|
||||
|
||||
lock curLng to pos:lng.
|
||||
|
||||
DECLARE LOCAL tgtLng IS burnLng - 5.
|
||||
if curLng > burnLng or curLng < tgtLng {
|
||||
SET WARPMODE TO "RAILS".
|
||||
SET WARP TO 3.
|
||||
print "warping to " + tgtLng.
|
||||
WAIT UNTIL curLng > tgtLng and curLng < burnLng.
|
||||
SET WARP TO 0.
|
||||
print "arived at dst " + tgtLng.
|
||||
print "burn at " + burnLng.
|
||||
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.
|
||||
}
|
||||
print "currently at" + curLng.
|
||||
|
||||
BRAKES ON.
|
||||
RCS ON.
|
||||
LOCK steering to retrograde.
|
||||
wait until curLng >= burnLng.
|
||||
|
||||
}
|
||||
|
||||
function CalculateBurnDuration{
|
||||
parameter dv.
|
||||
|
||||
declare local isp is GetIsp().
|
||||
declare local finalMass is mass * exp(-dv / (isp * constant:g0)).
|
||||
declare local twr is ship:maxThrust / (((mass + finalMass)/2) * constant:g0).
|
||||
|
||||
|
||||
local t is dv / (twr * constant.g0).
|
||||
return t.
|
||||
}
|
||||
|
||||
function GetIsp{
|
||||
LIST ENGINES IN allEngines.
|
||||
declare local totalThrust is ship:maxThrust.
|
||||
local sum is 0.
|
||||
local weights is 0.
|
||||
for eng in allEngines{
|
||||
if eng:IGNITION and not eng:flameout{
|
||||
local w is eng:AVAILABLETHRUST / totalThrust.
|
||||
local ispW is eng:isp * w.
|
||||
set sum to sum + ispW.
|
||||
set weights to weights + w.
|
||||
}
|
||||
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.
|
||||
}
|
||||
return sum / weights.
|
||||
}
|
||||
|
||||
// DeOrbit(-126, 250).
|
||||
print CalculateBurnDuration(250).
|
||||
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().
|
||||
|
||||
|
||||
Reference in New Issue
Block a user