Compare commits
No commits in common. "0e6904da890a22fd41b4923e812df82aa0b849a2" and "5193fc9d684e77a67499d5eb0e9ca4c5c497f480" have entirely different histories.
0e6904da89
...
5193fc9d68
3 changed files with 16 additions and 23 deletions
27
lib/node.ks
27
lib/node.ks
|
@ -10,20 +10,17 @@ function estimated_burn_duration {
|
||||||
// Based on:
|
// Based on:
|
||||||
// https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation
|
// 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
|
// https://space.stackexchange.com/questions/27375/how-do-i-calculate-a-rockets-burn-time-from-required-velocity
|
||||||
// https://www.alternatewars.com/BBOW/Space/Rocket_Equations.htm
|
|
||||||
//
|
//
|
||||||
parameter burn.
|
parameter burn.
|
||||||
parameter isp is isp_sum().
|
parameter isp is isp_sum().
|
||||||
parameter thrust is SHIP:availablethrust.
|
parameter maxthrust is SHIP:maxthrust.
|
||||||
|
|
||||||
if burn:istype("Node") {
|
if burn:istype("Node") {
|
||||||
set burn to burn:deltav.
|
set burn to burn:deltav.
|
||||||
}
|
}
|
||||||
|
|
||||||
local deltav is burn:mag.
|
local exhaust_velocity is isp * (CONSTANT:G * KERBIN:mass).
|
||||||
local exhaust_velocity is isp * CONSTANT:g0.
|
return ((SHIP:mass * exhaust_velocity) / maxthrust) * (1 - CONSTANT:E^(-burn:mag/exhaust_velocity)).
|
||||||
local wet_mass is SHIP:mass.
|
|
||||||
return ((wet_mass * exhaust_velocity) / thrust) * (1 - CONSTANT:E^(-deltav/exhaust_velocity)).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,20 +71,20 @@ function execute_burn {
|
||||||
lock STEERING to node.
|
lock STEERING to node.
|
||||||
wait until vang(SHIP:facing:vector, node:burnvector) <= 0.5.
|
wait until vang(SHIP:facing:vector, node:burnvector) <= 0.5.
|
||||||
|
|
||||||
// Start time is based on half of the delta-v instead of half the burn time to account for the acceleration increasing
|
local warp_time is max(0, node:eta - (burn_duration/2) - 5). // 5s before we need to start burn
|
||||||
// over the course of the burn as the rocket uses fuel, and thus the 2nd half of the burn will take less time than the first.
|
if warp_time {
|
||||||
local burn_start_time is TIME:seconds + node:eta - estimated_burn_duration(node:deltav/2).
|
print "Warping to maneuver node".
|
||||||
warp_to(burn_start_time - 3). // 3s before we need to start burn
|
warp_for(warp_time).
|
||||||
|
|
||||||
print "Approaching maneuver node".
|
print "Approaching maneuver node".
|
||||||
wait until TIME:seconds >= burn_start_time.
|
wait until node:eta <= ceiling(burn_duration/2). // ceiling since we'd rather start the burn too soon to have time for perfecting it
|
||||||
|
}
|
||||||
|
|
||||||
print "Burn!".
|
print "Burn!".
|
||||||
// Decrease throttle linearly with burn duration when under 1 second, but ensure we always finish by burning with at least 1% power at all times.
|
// Decreasing throttle linearly with burn duration will only have an effect below 1s, otherwise it will be at max
|
||||||
lock THROTTLE to max(0.01, min(1.0, burn_duration)).
|
lock THROTTLE to max(0.01, burn_duration). // ensure we always finish the burn by burning with at least 1% power at all times
|
||||||
|
|
||||||
// The burn vector will start to drift once we have very little left to burn.
|
// The burn vector will start to drift once we have very little left to burn. Therefore, save the burn vector as it is right now, and lock steering to it, instead of the dynamic vector
|
||||||
// Therefore, save the burn vector as it is right now, and lock steering to it, instead of the dynamic vector
|
|
||||||
wait until burn_duration <= 1.
|
wait until burn_duration <= 1.
|
||||||
local dv0 is node:burnvector.
|
local dv0 is node:burnvector.
|
||||||
lock STEERING to dv0.
|
lock STEERING to dv0.
|
||||||
|
|
|
@ -86,6 +86,5 @@ function rcs_translate {
|
||||||
local z is pid_z:update(TIME:seconds, relative_velocity():z).
|
local z is pid_z:update(TIME:seconds, relative_velocity():z).
|
||||||
|
|
||||||
set SHIP:CONTROL:TRANSLATION to ship_raw_to_ship_control(V(x,y,z)).
|
set SHIP:CONTROL:TRANSLATION to ship_raw_to_ship_control(V(x,y,z)).
|
||||||
wait 0. // wait one physics tick
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,13 @@
|
||||||
function warp_to {
|
function warp_to {
|
||||||
parameter timestamp.
|
parameter timestamp.
|
||||||
|
|
||||||
if timestamp <= TIME:seconds {
|
|
||||||
return.
|
|
||||||
}
|
|
||||||
|
|
||||||
print "Warping for " + round(timestamp - TIME:seconds, 1) + " seconds".
|
|
||||||
KUNIVERSE:timewarp:warpto(timestamp). // TODO: improve.
|
KUNIVERSE:timewarp:warpto(timestamp). // TODO: improve.
|
||||||
wait until TIME:seconds >= timestamp. // TODO
|
wait until TIME:seconds >= timestamp. // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
function warp_for {
|
function warp_for {
|
||||||
parameter seconds.
|
parameter seconds.
|
||||||
|
|
||||||
|
print "Warping for " + round(seconds, 1) + " seconds".
|
||||||
return warp_to(TIME:seconds + seconds).
|
return warp_to(TIME:seconds + seconds).
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue