finalized raden launch
wip landing script
This commit is contained in:
112
library/lib_vessel_utils.ks
Normal file
112
library/lib_vessel_utils.ks
Normal file
@@ -0,0 +1,112 @@
|
||||
run "library/lib_math".
|
||||
|
||||
declare function WaitForEngineStart{
|
||||
wait until AnyEngineActive().
|
||||
}
|
||||
|
||||
declare function AnyEngineActive{
|
||||
list engines in allEngines.
|
||||
for eng in allEngines{
|
||||
if eng:ignition {
|
||||
return true.
|
||||
}
|
||||
}
|
||||
return false.
|
||||
}
|
||||
|
||||
declare 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.
|
||||
}
|
||||
}
|
||||
return sum / weights.
|
||||
}
|
||||
|
||||
declare function GetMaxMassFlow{
|
||||
LIST ENGINES IN allEngines.
|
||||
local sum is 0.
|
||||
for eng in allEngines{
|
||||
if eng:IGNITION and not eng:flameout{
|
||||
set sum to sum + eng:maxmassflow.
|
||||
}
|
||||
}
|
||||
return sum.
|
||||
}
|
||||
|
||||
declare function CalculateSuicideBurnAltitude
|
||||
{
|
||||
parameter vertSpeed.
|
||||
parameter localGravity.
|
||||
parameter tgtAltitude is 0.
|
||||
|
||||
local burnAltitude is ((vertSpeed^2) / (2 * CalculateAverageAcceleration(localGravity))).
|
||||
return burnAltitude + tgtAltitude.
|
||||
}
|
||||
|
||||
|
||||
declare function CalculateSuicideBurnDuration
|
||||
{
|
||||
parameter isp.
|
||||
return CalculateBurnDuration(verticalSpeed, isp, ship:mass, GetMaxMassFlow() * 1000).
|
||||
}
|
||||
|
||||
declare function CalculateBurnDuration
|
||||
{
|
||||
parameter dv.
|
||||
parameter burnIsp.
|
||||
parameter initialMass.
|
||||
parameter massFlow.
|
||||
|
||||
set dv to abs(dv).
|
||||
local exp is -dv / (burnIsp * constant:g0).
|
||||
local massRatio is ApproximateExp(-exp).
|
||||
local finalMass is initialMass / massRatio.
|
||||
local fuelUsed is initialMass - finalMass.
|
||||
|
||||
if massFlow <= 0{
|
||||
return 0.
|
||||
}
|
||||
|
||||
return fuelUsed / massFlow.
|
||||
}
|
||||
|
||||
|
||||
declare function CalculateAverageAcceleration{
|
||||
parameter localGravity.
|
||||
return ((ship:maxthrust * 1000) / ship:mass) - localGravity.
|
||||
}
|
||||
|
||||
declare function GetLocalGravity{
|
||||
parameter curAltitude is -1.
|
||||
|
||||
if curAltitude = -1 {
|
||||
set curAltitude to altitude.
|
||||
}
|
||||
return body:mu / (curAltitude + body:radius)^2.
|
||||
}
|
||||
|
||||
declare function CalculateTimeToImpact{
|
||||
parameter vertSpeed.
|
||||
parameter curAltitude.
|
||||
parameter gravity.
|
||||
parameter tgtAltitude is 0.
|
||||
|
||||
if gravity <= 0 or curAltitude <= 0{
|
||||
print "[warn]: invalid altitude or gravity.".
|
||||
return 0.
|
||||
}
|
||||
|
||||
local vs is abs(vertSpeed).
|
||||
local g is gravity.
|
||||
local hRel is curAltitude - tgtAltitude.
|
||||
local disc is ((vs^2) + (2 * g * hRel)).
|
||||
return (vs + sqrt(disc)) / g.
|
||||
}
|
||||
Reference in New Issue
Block a user