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"). runoncepath("lib/throttle").
SAS off. SAS off.
local t is BurnTime(NEXTNODE:DELTAV:MAG)/2. local t is BurnTime(NEXTNODE:DELTAV:MAG).
print "Adjusting heading". print "Adjusting heading".
lock STEERING to NEXTNODE:DELTAV. lock STEERING to NEXTNODE:DELTAV.
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1. wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
print "Warping to node.". print "Warping to node.".
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - t - 5). KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - (t/2) - 5).
wait until NEXTNODE:ETA <= t. wait until NEXTNODE:ETA <= (t/2).
// todo: pid loop here or nah? overshoot would be tricky to deal with... // todo: pid loop here or nah? overshoot would be tricky to deal with...
print "Executing burn.". print "Executing burn.".
local throt is 1.0. local throt is 1.0.
lock THROTTLE to throt. lock THROTTLE to throt.
local dvLast is NEXTNODE:DELTAV:MAG. 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 wait 0.001. // make sure these control updates get applied
print "Target apoapsis acquired. Creating maneuver node.". print "Target apoapsis acquired. Creating maneuver node.".
AddCircularizationNode(). add CreateCircularizationNode().
runpath("/execnode"). runpath("/execnode").
print "Orbit acquired. Releasing controls. Good luck, Kerman.". print "Orbit acquired. Releasing controls. Good luck, Kerman.".
unlock THROTTLE. unlock THROTTLE.

View File

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

View File

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