Files
kylejennings5 dceeddfcf1 feat: overhaul lander suicide burn, add transfer GUI, improve ascent fairing logic
- lander.ks: Replace fixed suicide burn with dynamic throttle control using
  vertical fraction, gateRatio, and finalPhase logic; simplify post-land
  sequence to SAS stabilityassist
- transfer.ks: Replace hardcoded Mun target with GUI popup menu populated
  from body:orbitingchildren
- ascent.ks: Change fairing jettison trigger from dynamic pressure to
  altitude > atm height; guard antenna extension with hasmodule check
- basic.ks: Append stayRunner invocation at end of script
- boot/boot.ks: Remove commented RT connection block; add newline before runPath
- boot/testing.ks: Switch to volume 0 and use relative paths for transfer
  and doManeuver scripts
- boot/heloBoot.ks: Delete unused boot file
2026-06-26 17:44:06 -07:00

89 lines
3.1 KiB
Plaintext

function hohmannDeltaV {
parameter r1 is 1, r2 is 1, mu is 1.
local vCirc to sqrt(mu / r1).
local vHohmann to sqrt(mu * (2 / r1 - 2 / (r1 + r2))).
return vHohmann - vCirc.
}
function angleBetween {
parameter posA to V(1, 1, 0), posB to V(1, 1, 0).
local angle to arcTan2(posB:y, posB:x) - arcTan2(posA:y, posA:x).
if angle < 0 set angle to angle + 2 * constant:pi.
return angle.
}
function hohmannTransfer {
// parameter targetPeriapsis is 60000.
parameter tgtBody is Mun.
// get the approximate required deltav for a transfer
local r1 to ship:orbit:semimajoraxis.
local r2 to tgtBody:orbit:semimajoraxis.
local vTransfer to hohmannDeltaV(r1, r2, kerbin:mu).
// compute the transfer time
local transferSMA to (r1 + r2) / 2.
local transferPeriod to 2 * constant:pi * sqrt(transferSMA^3 / kerbin:mu).
local transitTime to transferPeriod / 2.
// get lead angle (how far ahead the tgtBody must be)
local tgtAV to 2 * constant:pi / tgtBody:orbit:period.
local leadAngle to tgtAV * transitTime.
local transferAngle to constant:pi - leadAngle.
// find the next time the phase angle condition is satisfied
local shipAV to 2 * constant:pi / ship:orbit:period.
local relativeAV to tgtAV - shipAV.
// get the phase angle to the target
local bodyToShip to (ship:position - body:position):normalized.
local obtNorm to vCrs(bodyToShip, ship:velocity:orbit:normalized):normalized.
local bodyToTgt to vXcl(obtNorm, (tgtBody:position - body:position):normalized):normalized.
local signVec to vCrs(obtNorm, bodyToShip):normalized.
local phaseSign to vDot(bodyToTgt, signVec).
local currentPhaseAngle to vAng(ship:position - body:position, tgtBody:position - body:position) * (constant:pi / 180).
if phaseSign < 0 set currentPhaseAngle to -1 * currentPhaseAngle + 2 * constant:pi.
// get the time to start the maneuver
local phaseError is transferAngle - currentPhaseAngle.
if phaseError < 0 set phaseError to phaseError + 2 * constant:pi.
local waitTime to phaseError / relativeAV.
if waitTime < 0 set waitTime to waitTime + ship:orbit:period.
set nd to node(time:seconds + waitTime, 0, 0, vTransfer).
add nd.
// print "Transfer DeltaV (m/s) : " + round(vTransfer, 2).
// print "Transit Time (s) : " + round(transitTime*57.3, 0).
// print "Lead Angle (deg) : " + round(transferAngle*57.3, 2).
// print "Relative AV (deg/s) : " + relativeAV*57.3.
// print "Phase Angle (deg) : " + round(currentPhaseAngle*57.3, 2).
// print "Phase Error (deg) : " + round(phaseError*57.3, 2).
// print "Wait Time (s) : " + round(waitTime, 0).
}
local g is GUI(300).
set g:x to 100.
set g:y to 100.
local titleLabel is g:addlabel("Transfer to which body?").
set titleLabel:style:align to "center".
set titleLabel:style:hstretch to true.
local popup is g:addpopupmenu().
set popup:optionsuffix to "NAME".
for localMoon in body:orbitingchildren popup:addoption(localMoon).
popup:changed.
// print popup:options.
// print popup:changed.
g:show().
wait until popup:changed.
// print popup:value.
g:dispose().
hohmannTransfer(popup:value).