Fix multi-stage node execution.
This commit is contained in:
parent
92b6345f3e
commit
9b0792b81a
29
lib/node.ks
29
lib/node.ks
|
@ -39,10 +39,11 @@ function ExecNode {
|
||||||
print "Node execution complete.".
|
print "Node execution complete.".
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// currently only works for testing against *current* stage.
|
||||||
function WillStage {
|
function WillStage {
|
||||||
parameter dV.
|
parameter dV.
|
||||||
if not HASNODE { return false. }
|
if not HASNODE { return false. }
|
||||||
return dV > NEXTNODE:DELTAV:MAG.
|
return dV > SHIP:StageDeltaV(SHIP:STAGENUM):VACUUM.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the time required to burn a given dV.
|
// Calculate the time required to burn a given dV.
|
||||||
|
@ -54,19 +55,18 @@ function BurnTime {
|
||||||
local lastStage is false.
|
local lastStage is false.
|
||||||
// We allow a small tolerance to deal with potential floating point errors.
|
// We allow a small tolerance to deal with potential floating point errors.
|
||||||
until totaldV <= 0.001 {
|
until totaldV <= 0.001 {
|
||||||
local F is stageThrust().
|
local F is stageThrust(s).
|
||||||
local Isp is stageISP().
|
local Isp is stageISP(s).
|
||||||
local m is stageMass(s).
|
local m is stageMass(s).
|
||||||
// TODO: handle node execution in atmosphere?
|
// 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.".
|
|
||||||
set totaldV to totaldV - dV.
|
set totaldV to totaldV - dV.
|
||||||
set s to s - 1.
|
set s to s - 1.
|
||||||
set totalT to totalT + t.
|
set totalT to totalT + t.
|
||||||
}
|
}
|
||||||
|
|
||||||
print "DEBUG: Total Burn Time: " + totalT + " s.".
|
|
||||||
return totalT.
|
return totalT.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,10 @@ function BurnTime {
|
||||||
function calcBurnTime {
|
function calcBurnTime {
|
||||||
parameter dV, m, Isp, F.
|
parameter dV, m, Isp, F.
|
||||||
|
|
||||||
if F = 0 {
|
if F = 0 or Isp = 0 {
|
||||||
print "WARNING: Tried to calculate burn time with a thrust of 0. Returning 0. Your calculations are probably wrong.".
|
print "WARNING: Tried to calculate burn time with a denominator value of 0. Returning 0. Your calculations are probably wrong.".
|
||||||
|
print "F: " + F .
|
||||||
|
print "Isp: " + Isp.
|
||||||
return 0.
|
return 0.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ function stageISP {
|
||||||
local eCount is 0.
|
local eCount is 0.
|
||||||
for e in en {
|
for e in en {
|
||||||
if e:STAGE >= s and e:DECOUPLEDIN < s {
|
if e:STAGE >= s and e:DECOUPLEDIN < s {
|
||||||
set ispSum to ispSum + e:ISP.
|
set ispSum to ispSum + e:VACUUMISP.
|
||||||
set eCount to eCount + 1.
|
set eCount to eCount + 1.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,11 +141,14 @@ function stageMass {
|
||||||
local ps is List().
|
local ps is List().
|
||||||
list PARTS in ps.
|
list PARTS in ps.
|
||||||
for part in ps {
|
for part in ps {
|
||||||
if part:DECOUPLEDIN <= s {
|
if part:DECOUPLEDIN >= s {
|
||||||
set m to m - part:MASS.
|
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.
|
|
||||||
|
list ENGINES in ps.
|
||||||
|
for part in ps {
|
||||||
|
if part:DECOUPLEDIN < s and part:AVAILABLETHRUST > 0 {
|
||||||
set m to m - (part:MAXMASSFLOW * SHIP:StageDeltaV(SHIP:STAGENUM):DURATION).
|
set m to m - (part:MAXMASSFLOW * SHIP:StageDeltaV(SHIP:STAGENUM):DURATION).
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user