Refactor some functions only used once.

This commit is contained in:
Anna Rose 2021-08-10 18:17:05 -04:00
parent e03222bac2
commit 310a3fb372
2 changed files with 21 additions and 18 deletions

View File

@ -2,6 +2,26 @@ runoncepath("lib/throttle").
runoncepath("lib/navigation"). runoncepath("lib/navigation").
runoncepath("lib/node"). runoncepath("lib/node").
// Calculate the vector at which to ascend.
// This is basically prograde plus some anti-rotation logic and a lower bound.
function getAscentVector {
parameter minPitch.
// face prograde, but hold a solid eastern heading and don't
// rotate the ship
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
heading(90, 0, 270):TOPVECTOR).
if getPitch(newHeading:FOREVECTOR) < minPitch {
set newHeading to heading(90, minPitch, 270).
}
return newHeading.
}
// Returns the navball pitch of a given vector.
function getPitch {
parameter v is SHIP:FACING:FOREVECTOR.
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
}
function Launch { function Launch {
parameter APOAPSIS_TARGET is 80000. parameter APOAPSIS_TARGET is 80000.
parameter ATMO_TWR is 1.6. parameter ATMO_TWR is 1.6.
@ -60,7 +80,7 @@ function Launch {
wait until GetPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= targetPitch. wait until GetPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= targetPitch.
print "Locking to prograde, letting gravity do the hard work.". print "Locking to prograde, letting gravity do the hard work.".
lock STEERING to GetAscentVector(MINIMUM_PITCH). lock STEERING to getAscentVector(MINIMUM_PITCH).
wait until SHIP:ALTITUDE > 32000. // todo: if we have a pressure sensor we can use it to decide when to kick the throttle up instead, neat solution for e.g. Duna and Eve. wait until SHIP:ALTITUDE > 32000. // todo: if we have a pressure sensor we can use it to decide when to kick the throttle up instead, neat solution for e.g. Duna and Eve.
lock THROTTLE to 1.0. lock THROTTLE to 1.0.

View File

@ -1,22 +1,5 @@
// functions for calculating steering values. // functions for calculating steering values.
function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR.
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
}
function GetAscentVector {
parameter minPitch.
// face prograde, but hold a solid eastern heading and don't
// rotate the ship
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
heading(90, 0, 270):TOPVECTOR).
if GetPitch(newHeading:FOREVECTOR) < minPitch {
set newHeading to heading(90, minPitch, 270).
}
return newHeading.
}
// Create a node that will circularize the orbit. // Create a node that will circularize the orbit.
// 'where' can be one of: // 'where' can be one of:
// the special string "APO", for the next Apoapsis. // the special string "APO", for the next Apoapsis.