Various improvements, oops.

This commit is contained in:
2021-07-21 05:24:46 -04:00
parent e2653db827
commit c7438fcfe7
4 changed files with 125 additions and 72 deletions

View File

@ -1,7 +1,8 @@
// Functions for calculating thrust values.
@lazyglobal off.
local G is 9.81.
// point gravity for TWR calculations.
local G is 0.
lock G to SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2).
// Returns the throttle value you should use to achieve the
@ -22,25 +23,21 @@ function TWR {
// Calculate the time required to burn a given dV at a given altitude.
// Must be called while in the same SOI as the burn itself.
// Assumes a perfectly spherical Kerbal in a vacuum.
function BurnTime {
parameter dV, a, m is SHIP:MASS, s is STAGE:NUMBER.
parameter dV, m is SHIP:MASS, s is STAGE:NUMBER.
local Gb is SHIP:BODY:MU / ((SHIP:BODY:RADIUS+a)^2).
local f is stageThrust(). // Engine Thrust (kg * m/s²)
local Isp is stageISP(). // Engine ISP (s)
// debug
print "Calculating burn time.".
print "dV = " + dV.
print "f = " + f.
print "m = " + m.
print "e = " + e.
print "Isp = " + Isp.
print "Gb = " + Gb.
// end debug
if dV > SHIP:STAGEDELTAV(s) {
local t is burnTimeCalc(SHIP:STAGEDELTAV(s), m, Gb, Isp, f).
local dVs is SHIP:StageDeltaV(s):VACUUM.
if dV > dVs {
// TODO: not 100% this is needed vs using DeltaV:DURATION.
// Docs suggest DeltaV:DURATION is not entirely reliable, however.
// For now we're logging both values for comparison.
local t is burnTimeCalc(dVs, m, Isp, f).
print "Computed stage burn time = " + t.
print "KSC-estimated stage burn time = " + SHIP:StageDeltaV(s):DURATION.
local parts is list().
for part in parts {
@ -49,15 +46,15 @@ function BurnTime {
}
}
return t + BurnTime(dV - SHIP:STAGEDELTAV(s), a, m, s - 1).
return t + BurnTime(dV - SHIP:STAGEDELTAV(s):VACUUM, m, s - 1).
}
return burnTimeCalc(dV, m, Gb, Isp, f).
return burnTimeCalc(dV, m, Isp, f).
}
// Convenience function to wrap the actual calculation for burn time.
function burnTimeCalc {
parameter dV, m, Gb, Isp, f.
parameter dV, m, Isp, f.
if f = 0 {
print "WARNING: Tried to calculate burn time with a thrust of 0. Returning 0. Your calculations are probably wrong.".
@ -69,7 +66,8 @@ function burnTimeCalc {
// which is suggested at https://www.reddit.com/r/Kos/comments/lev9pw/getting_burntime_from_next_stage/gmig0hl/?context=8&depth=9
// are they equivalent? Is one better than the other? This one doesn't require
// knowing final mass, which is nice.
return Gb * m * Isp * (1 - CONSTANT():E^(-dV/(Gb*Isp))) / f.
local g0 is CONSTANT:G0.
return g0 * m * Isp * (1 - CONSTANT():E^(-dV/(g0*Isp))) / f.
}
// Calculate the ISP for a given stage.