finalized raden launch

wip landing script
This commit is contained in:
2025-11-20 01:29:40 -05:00
parent 533ec9d520
commit b90b0157e4
8 changed files with 315 additions and 74 deletions

View File

@@ -1,15 +1,30 @@
declare function lerp{
declare function Lerp{
parameter a.
parameter b.
parameter t.
return a + (b - a) * t.
}
declare function map{
parameter a1.
parameter b1.
parameter a2.
parameter b2.
parameter v.
return a2 + (v - a1) * (b2 - a2) / (b1 - a1).
declare function Map{
parameter value.
parameter low1.
parameter high1.
parameter low2.
parameter high2.
return low2 + (high2 - low2) * ((value - low1) / (high1 - low1)).
}
declare function ApproximateExp {
parameter x.
local result is 1.0.
local xPower is 1.0.
local nFact is 1.0.
// Loop 4 times (for terms 1 through 4, total 5 terms)
from { local n is 1.} until n = 5 step {set n to n + 1.} do {
SET xPower TO xPower * x.
SET nFact TO nFact * n.
SET result TO result + (xPower / nFact).
}
RETURN result.
}

112
library/lib_vessel_utils.ks Normal file
View 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.
}