Improvements to node execution, including attempt at better node time calculations and automatic staging.
This commit is contained in:
parent
102786b79b
commit
429a1d5302
57
lib/node.ks
57
lib/node.ks
|
@ -11,8 +11,16 @@ function ExecNode {
|
||||||
local leadT is BurnTime(NEXTNODE:DELTAV:MAG / 2).
|
local leadT is BurnTime(NEXTNODE:DELTAV:MAG / 2).
|
||||||
local t is BurnTime(NEXTNODE:DELTAV:MAG).
|
local t is BurnTime(NEXTNODE:DELTAV:MAG).
|
||||||
|
|
||||||
|
if willStage(NEXTNODE:DELTAV:MAG) {
|
||||||
|
print "WARNING: kOS will stage during this node execution. Safe cancellation requires reboot.".
|
||||||
|
when flameOut() then {
|
||||||
|
print "Flameout detected. Staging.".
|
||||||
|
stage.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print "Adjusting heading".
|
print "Adjusting heading".
|
||||||
lock STEERING to NEXTNODE:DELTAV.
|
lock STEERING to LookDirUp(NEXTNODE:DELTAV, SHIP:FACING:TOPVECTOR).
|
||||||
wait until VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
|
wait until VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
|
||||||
|
|
||||||
print "Warping to node.".
|
print "Warping to node.".
|
||||||
|
@ -34,12 +42,16 @@ function ExecNode {
|
||||||
// Calculate the time required to burn a given dV.
|
// Calculate the time required to burn a given dV.
|
||||||
// Assumes a perfectly spherical Kerbal in a vacuum.
|
// Assumes a perfectly spherical Kerbal in a vacuum.
|
||||||
function BurnTime {
|
function BurnTime {
|
||||||
parameter totaldV, m is SHIP:MASS, s is STAGE:NUMBER.
|
parameter totaldV, s is STAGE:NUMBER.
|
||||||
local totalT is 0.0.
|
local totalT is 0.0.
|
||||||
|
|
||||||
until totaldV <= 0 {
|
local lastStage is false.
|
||||||
|
// We allow a small tolerance to deal with potential floating point errors.
|
||||||
|
until totaldV <= 0.001 {
|
||||||
local F is stageThrust().
|
local F is stageThrust().
|
||||||
local Isp is stageISP().
|
local Isp is stageISP().
|
||||||
|
local m is stageMass(s).
|
||||||
|
// TODO: handle node execution in atmosphere?
|
||||||
local dV is min(totaldV, SHIP:StageDeltaV(s):VACUUM).
|
local dV is min(totaldV, SHIP:StageDeltaV(s):VACUUM).
|
||||||
local t is calcBurnTime(dV, m, Isp, F).
|
local t is calcBurnTime(dV, m, Isp, F).
|
||||||
print "DEBUG: " + dV + " m/s^2 in stage " + s + ", in " + t + " seconds.".
|
print "DEBUG: " + dV + " m/s^2 in stage " + s + ", in " + t + " seconds.".
|
||||||
|
@ -48,6 +60,7 @@ function BurnTime {
|
||||||
set totalT to totalT + t.
|
set totalT to totalT + t.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print "DEBUG: Total Burn Time: " + totalT + " s.".
|
||||||
return totalT.
|
return totalT.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,3 +117,41 @@ function stageThrust {
|
||||||
|
|
||||||
return sum.
|
return sum.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine mass at start of target stage.
|
||||||
|
// This can handle Delta V-style launchers but
|
||||||
|
// only if the central rocket remains in the stack
|
||||||
|
// for exactly two stages, one of which is the current stage.
|
||||||
|
// More complex staging with partially depleted tanks may produce
|
||||||
|
// undefined behavior.
|
||||||
|
function stageMass {
|
||||||
|
parameter s is STAGE:NUMBER.
|
||||||
|
|
||||||
|
local m is SHIP:MASS.
|
||||||
|
if s = SHIP:STAGENUM { return m. }
|
||||||
|
|
||||||
|
local ps is List().
|
||||||
|
list PARTS in ps.
|
||||||
|
for part in ps {
|
||||||
|
if part:DECOUPLEDIN <= s {
|
||||||
|
set m to m - part:MASS.
|
||||||
|
} else if part:HasSuffix("AVAILABLETHRUST") and part:AVAILABLETHRUST > 0 {
|
||||||
|
// This is an engine and it is currently active. Subtract the fuel
|
||||||
|
// it will burn before the next stage.
|
||||||
|
set m to m - (part:MAXMASSFLOW * SHIP:StageDeltaV(SHIP:STAGENUM):DURATION).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.
|
||||||
|
}
|
||||||
|
|
||||||
|
function flameOut {
|
||||||
|
local ens is List().
|
||||||
|
list engines in ens.
|
||||||
|
for en in ens {
|
||||||
|
if en:FLAMEOUT {
|
||||||
|
return true.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false.
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user