// ═══════════════════════════════════════════════════════════ // maneuver.ks // Utility functions related to maneuvers. // // Usage: // executeNode(nd: node) // ═══════════════════════════════════════════════════════════ // #include staging run once staging. function executeNode { parameter nd is node(0, 0, 0, 0). print "boof". if nd:deltav:mag = 0 { print "Empty node". return. } local burnTime to calcBurnTime(nd:deltav:mag). print "Node in: " + round(nd:eta) + "s, dV: " + round(nd:deltav:mag, 1) + " m/s, burn time: " + round(burnTime, 1) + "s". // wait for node to be close then align to vector wait until nd:eta <= burnTime / 2 + 60. local np to nd:deltav. lock steering to np. wait until vang(ship:facing:vector, nd:deltav) < 1. print "Maneuver vector lined up". // wait until burn wait until nd:eta <= burnTime / 2. print "Burn time". // ── Snapshot initial dV for overburn detection local dv0 to nd:deltav. local throttleSet to 0. lock throttle to throttleSet. // ag1 off. // until ag1 { until False { local maxAcc to ship:maxThrust / ship:mass. set throttleSet to min(nd:deltav:mag / maxAcc, 1). set np to nd:deltav. // ── Overburn detection if vdot(dv0, nd:deltav) < 0 { print "Overburn detected. Cutting throttle.". lock throttle to 0. break. } // ── Residual dV negligible if nd:deltav:mag < 0.1 { wait until vdot(dv0, nd:deltav) < 0.5. lock throttle to 0. break. } wait 0. } lock throttle to 0. unlock throttle. unlock steering. remove nd. } function createCircularizationNodeAp { local rBurn to body:radius + apoapsis. local vTarget to sqrt(body:mu / rBurn). local dvEst to vTarget - velocityat(ship, time:seconds + eta:apoapsis):orbit:mag. local nd to node(time:seconds + eta:apoapsis, 0, 0, dvEst). add nd. return nd. } function createCircularizationNodePe { local rBurn to body:radius + periapsis. local vTarget to sqrt(body:mu / rBurn). local dvEst to vTarget - velocityat(ship, time:seconds + eta:periapsis):orbit:mag. local nd to node(time:seconds + eta:periapsis, 0, 0, dvEst). add nd. return nd. }