From d44ed775df42f8ce4ff9074843e6d32825837085 Mon Sep 17 00:00:00 2001 From: annabunches Date: Wed, 29 Sep 2021 03:26:15 -0400 Subject: [PATCH] Fix staging and burn angle. --- lib/launch_rocket.ks | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/launch_rocket.ks b/lib/launch_rocket.ks index d7ed9b0..11bd353 100644 --- a/lib/launch_rocket.ks +++ b/lib/launch_rocket.ks @@ -108,6 +108,8 @@ function Launch { // serves the specific needs of launch. // It also makes automated launches possible before maneuver nodes are unlocked. // +// TODO: Refactor code reuse between this function and ExecNode(). +// // prerequisites: // * Vessel is still behind the Apoapsis // * Apoapsis is at the target height @@ -116,7 +118,7 @@ function insertionBurn { // vector is prograde but only on the horizonal plane print "Adjusting heading.". - local horizon is Vxcl(SHIP:UP:FOREVECTOR, SHIP:PROGRADE:FOREVECTOR). + local lock horizon is Vxcl(SHIP:UP:FOREVECTOR, SHIP:PROGRADE:FOREVECTOR). lock STEERING to LookDirUp(horizon, SHIP:FACING:TOPVECTOR). // calculate the deltaV to get us to the target velocity, for calculating burn start time. @@ -124,15 +126,22 @@ function insertionBurn { local Vc is sqrt(SHIP:BODY:MU/(PositionAt(SHIP, t) - SHIP:BODY:POSITION):MAG). local dV is Vc - VelocityAt(SHIP, t):ORBIT:MAG. + if WillStage(dV) { + when FlameOut() then { + print "Flameout detected. Staging.". + stage. + } + } + // calculate the total burn time (Tb) and the burn start time (Ts) local Tb is BurnTime(dV). local Ts is TIME + SHIP:OBT:ETA:APOAPSIS - BurnTime(dV / 2). // warp to the burn point print "Waiting for burn window.". - wait until (VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 1) OR (TIME > Ts). + wait until (VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.5) OR (TIME > Ts). if TIME < Ts - 2 { - KUNIVERSE:TIMEWARP:WarpTo(Ts - 2). + KUNIVERSE:TIMEWARP:WarpTo(Ts:SECONDS - 2). } wait until SHIP:UNPACKED. wait until TIME > Ts.