kOS-scripts/lib/orbital_maneuvers.ks

50 lines
1.8 KiB
Plaintext

@LAZYGLOBAL OFF.
run once "lib/orbital_equations".
run once "lib/node".
function change_orbit {
//
// Change current orbit. Set parameter to -1 to maintain the current value (TODO: all of this)
//
parameter inclination is ORBIT:inclination. // vertical tilt of the orbit with respect to the equator
parameter eccentricity is ORBIT:eccentricity. // how circular the orbit is (e=0 circular)
parameter periapsis is ORBIT:periapsis. // lowest point in the orbit
parameter lan is 0. // longitude of ascending node; the longitude where the orbit crosses the equator northwards
parameter argument_of_periapsis is ORBIT:argumentofperiapsis. // the angle from the ascending node to the periapsis, measured in the direction of motion
print inclination.
print eccentricity.
print periapsis.
print lan.
print argument_of_periapsis.
}
function circularize {
//
// Circularize orbit at the given target.
//
parameter target.
parameter eta. // eta to target
local node is NODE(TIME:SECONDS + eta, 0, 0, 0).
// Prograde burn magnitude is the difference between the required velocity to achieve circular orbit at target's altitude and our actual velocity at the target
local required_velocity is orbital_velocity_circular(target).
set node:prograde to required_velocity - velocityat(SHIP, TIME:seconds + eta):orbit:mag.
add node.
execute_burn(node).
}
function circularize_at_apoapsis {
print "Circularizing at apoapsis".
return circularize(APOAPSIS, ETA:APOAPSIS).
}
function circularize_at_periapsis {
print "Circularizing at periapsis".
return circularize(PERIAPSIS, ETA:PERIAPSIS).
}