kOS/rocket/execnode.ks

49 lines
1.1 KiB
Plaintext
Raw Normal View History

runoncepath("lib/navigation").
runoncepath("lib/throttle").
2021-07-19 07:43:07 +00:00
SAS off.
local t is BurnTime(NEXTNODE:DELTAV:MAG).
2021-07-19 07:43:07 +00:00
print "Adjusting heading".
lock STEERING to NEXTNODE:DELTAV.
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
2021-07-20 06:40:47 +00:00
print "Warping to node.".
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...
2021-07-20 06:40:47 +00:00
print "Executing burn.".
2021-07-21 09:24:46 +00:00
local dvMin is NEXTNODE:DELTAV:MAG.
local throt is 1.0.
lock THROTTLE to throt.
2021-07-21 09:24:46 +00:00
// debug
print "dVMin = " + dvMin.
print "dV = " + NEXTNODE:DELTAV:MAG.
// Execute the burn, throttling down by half every time we're
// consuming more than 25% of our dV in one update.
2021-07-21 09:24:46 +00:00
until NEXTNODE:DELTAV:MAG <= 0.25 or dVMin < NEXTNODE:DELTAV:MAG {
// debug
print "dVMin = " + dvMin.
print "dV = " + NEXTNODE:DELTAV:MAG.
if NEXTNODE:DELTAV:MAG < dVMin {
set dvMin to NEXTNODE:DELTAV:MAG.
}
2021-07-21 09:24:46 +00:00
wait 0.001.
}
2021-07-19 07:43:07 +00:00
unlock THROTTLE.
unlock STEERING.
SAS on.
2021-07-20 06:40:47 +00:00
print "Node execution complete.".
2021-07-21 09:24:46 +00:00
// debug
print "Final dVMin = " + dvMin.
print "Final dV = " + NEXTNODE:DELTAV:MAG.