Don't use custom align_with function (invites A LOT of trouble due to the way things are passed around in kOS).

This commit is contained in:
Casper V. Kristensen 2019-02-10 15:32:50 +01:00
parent 6de947fb18
commit 703afe4e8b
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 8 additions and 26 deletions

View file

@ -38,12 +38,12 @@ function vector_to_node {
local normal_at_time is vcrs(prograde_at_time, position_at_time). // vector cross product is a vector that is normal to the plane containing them (see image)
local radial_at_time is vcrs(normal_at_time, prograde_at_time).
// vdot input vector with components at given time to get its magnitude in these directions
// Project the given input vector onto the three components to find its magnitude at the given time
local vec_prograde_at_time is vdot(vec, prograde_at_time:normalized).
local vec_normal_at_time is vdot(vec, normal_at_time:normalized).
local vec_radial_at_time is vdot(vec, radial_at_time:normalized).
return node(time, vec_radial_at_time, vec_normal_at_time, vec_prograde_at_time).
return NODE(time, vec_radial_at_time, vec_normal_at_time, vec_prograde_at_time).
}
@ -62,10 +62,12 @@ function execute_burn {
local lock burn_duration to estimated_burn_duration(node).
print "==> EXECUTING MANEUVER NODE".
print "Estimated burn duration: " + round(burn_duration, 1) + "s".
print "Estimated burn duration: " + round(burn_duration, 2) + "s".
print "Aligning ship with burn vector".
align_with(node). // parsing node instead of its burnvector allows the steering lock to dynamically update
SAS off.
lock STEERING to node.
wait until vang(SHIP:facing:vector, node:burnvector) <= 0.5.
local warp_time is max(0, node:eta - (burn_duration/2) - 5). // 5s before we need to start burn
if warp_time {
@ -77,13 +79,11 @@ function execute_burn {
}
print "Burn!".
lock THROTTLE to 1.0.
// Decrease throttle linearly when the burn duration is less than 1 second
wait until burn_duration <= 1.
// 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, 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. 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.
local dv0 is node:burnvector.
lock STEERING to dv0.

View file

@ -67,24 +67,6 @@ function extend_antennas {
}
function align_with {
//
// Aligns the rocket with the given vector or node.
//
parameter direction. // Vector or Node
parameter tolerance is 0.5.
local alignment_vector is direction.
if direction:istype("Node") {
lock alignment_vector to direction:burnvector. // locking allows steering to dynamically update when the node does
}
SAS off.
lock STEERING to alignment_vector.
wait until vang(SHIP:facing:vector, alignment_vector) <= tolerance.
}
function unlock_control {
//
// Ensure that the throttle is 0 and that the player is not locked out of control.