Use orbital math to simplify circ node.

This commit is contained in:
Anna Rose 2021-07-20 04:18:16 -04:00
parent ec9568b24a
commit d27d63fb80
4 changed files with 17 additions and 27 deletions

View File

@ -2,18 +2,19 @@ runoncepath("lib/navigation").
runoncepath("lib/throttle").
SAS off.
local t is BurnTime(NEXTNODE:DELTAV:MAG)/2.
local t is BurnTime(NEXTNODE:DELTAV:MAG).
print "Adjusting heading".
lock STEERING to NEXTNODE:DELTAV.
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
print "Warping to node.".
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - t - 5).
wait until NEXTNODE:ETA <= t.
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - (t/2) - 5).
wait until NEXTNODE:ETA <= (t/2).
// todo: pid loop here or nah? overshoot would be tricky to deal with...
print "Executing burn.".
local throt is 1.0.
lock THROTTLE to throt.
local dvLast is NEXTNODE:DELTAV:MAG.

View File

@ -63,7 +63,7 @@ set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
wait 0.001. // make sure these control updates get applied
print "Target apoapsis acquired. Creating maneuver node.".
AddCircularizationNode().
add CreateCircularizationNode().
runpath("/execnode").
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
unlock THROTTLE.

View File

@ -18,26 +18,15 @@ function GetAscentVector {
return newHeading.
}
function AddCircularizationNode {
parameter usePeriapsis is false.
local target is SHIP:ORBIT:APOAPSIS.
local t is TIME + SHIP:ORBIT:ETA:APOAPSIS.
if usePeriapsis {
set target to SHIP:ORBIT:PERIAPSIS.
set t to SHIP:ORBIT:ETA:PERIAPSIS.
}
local n is Node(t, 0, 0, 0).
add(n).
function CreateCircularizationNode {
parameter nodeAtPeriapsis is false.
local epsilon is 100.
lock diff to n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS.
local pid is PIDLoop(0.05, 0.006, 0.006).
set pid:EPSILON to epsilon.
set pid:SETPOINT to n:ORBIT:APOAPSIS.
local dt is choose SHIP:ORBIT:ETA:PERIAPSIS if nodeAtPeriapsis else SHIP:ORBIT:ETA:APOAPSIS.
local t is TIME + dt.
until abs(diff) < epsilon {
set n:PROGRADE to pid:Update(TIME:SECONDS, n:ORBIT:PERIAPSIS).
wait 0.001.
}
print "Circularization node created."
local Vc is sqrt(SHIP:BODY:MU/(SHIP:BODY:RADIUS + SHIP:ORBIT:APOAPSIS)).
local dV is Vc - VelocityAt(SHIP, t):ORBIT:MAG.
local n is Node(t, 0, 0, dV).
return n.
}

View File

@ -61,7 +61,7 @@ set termButton:onClick to terminalButtonPressed@.
// debug
function circButtonPressed {
runpath("/lib/navigation").
AddCircularizationNode().
add CreateCircularizationNode().
}
local cButton is interface:AddButton("Circularize").
set cButton:onClick to circButtonPressed@.