kOS-scripts/node.ks

58 lines
1.8 KiB
Plaintext
Raw Normal View History

2018-07-19 14:42:03 +02:00
run once util.
function estimated_burn_duration {
// Calculate estimated burn duration for a maneuver node
2018-07-19 14:42:03 +02:00
// https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation
// https://space.stackexchange.com/questions/27375/how-do-i-calculate-a-rockets-burn-time-from-required-velocity
parameter node is NEXTNODE.
2018-07-19 14:42:03 +02:00
local exhaust_velocity is isp_sum() * (CONSTANT:G * KERBIN:MASS).
return ((SHIP:MASS * exhaust_velocity) / SHIP:MAXTHRUST) * (1 - CONSTANT:E^(-node:DELTAV:MAG/exhaust_velocity)).
}
function execute_node {
parameter node is NEXTNODE.
parameter precision is 0.05. // m/s delta-v
2018-07-19 14:42:03 +02:00
local burn_duration is estimated_burn_duration(node).
2018-07-19 14:42:03 +02:00
print "=== EXECUTE MANEUVER NODE ===".
print "Estimated burn duration: " + ROUND(burn_duration, 1) + "s".
print "Aligning ship with burn vector..".
2018-07-19 14:42:03 +02:00
SAS OFF.
lock STEERING to node:DELTAV.
wait until VANG(SHIP:FACING:VECTOR, node:DELTAV) < 0.1.
2018-07-19 14:42:03 +02:00
print "Initializing warp".
unlock_control().
warp_for(MAX(0, node:ETA - (burn_duration/2) - 5)). // warp until 5s before node
2018-07-19 14:42:03 +02:00
print "Approaching".
lock STEERING to node:DELTAV.
wait until node:ETA <= ROUND(burn_duration/2).
2018-07-19 14:42:03 +02:00
print "Burn!".
lock THROTTLE to 1.0.
// Decrease throttle linearly when the burn duration is less than 1 second
wait until estimated_burn_duration(node) <= 1.
lock THROTTLE to MAX(0.01, estimated_burn_duration(node)). // ensure we always finish by burning with at least 1% power
wait until node:DELTAV:MAG < precision.
2018-07-19 14:42:03 +02:00
set THROTTLE to 0.0.
print "=== MANEUVER NODE EXECUTED ===".
print ROUND(node:DELTAV:MAG, 3) + "m/s delta-v remaining".
unlock_control().
wait 1.
2018-07-19 14:42:03 +02:00
remove node.
}
function change_slash_set_orbit {
2018-07-19 14:42:03 +02:00
parameter what.
}