kOS/lib/navigation.ks

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-07-19 07:43:07 +00:00
// functions for calculating steering values.
@lazyglobal off.
function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR.
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
}
2021-07-19 07:43:07 +00:00
function GetAscentVector {
parameter minPitch.
// face prograde, but hold a solid eastern heading and don't
// rotate the ship
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
heading(90, 0, 270):TOPVECTOR).
if GetPitch(newHeading:FOREVECTOR) < minPitch {
set newHeading to heading(90, minPitch, 270).
}
return newHeading.
}
function AddCircularizationNode {
2021-07-19 07:43:07 +00:00
parameter usePeriapsis is false.
local target is SHIP:ORBIT:APOAPSIS.
local t is TIME + SHIP:ORBIT:ETA:APOAPSIS.
2021-07-19 07:43:07 +00:00
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.
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.
until abs(diff) < epsilon {
set n:PROGRADE to pid:Update(TIME:SECONDS, n:ORBIT:PERIAPSIS).
wait 0.001.
2021-07-19 07:43:07 +00:00
}
2021-07-20 06:40:47 +00:00
print "Circularization node created."
2021-07-19 07:43:07 +00:00
}