From 5cb608ff0121170e0d56537cd32832b36c3d9985 Mon Sep 17 00:00:00 2001 From: annabunches Date: Sun, 18 Jul 2021 16:06:38 -0400 Subject: [PATCH] Fix throttling, first attempt to fix gravity turn. --- boot/rocket.ks | 2 +- launch.ks | 16 ++++++++++------ lib/guidance.ks | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/boot/rocket.ks b/boot/rocket.ks index 7485fa9..8a5fb47 100644 --- a/boot/rocket.ks +++ b/boot/rocket.ks @@ -1,5 +1,5 @@ COPYPATH("0:/noop", ""). COMPILE "0:/launch" to "1:/launch". -COMPILE "0:/lib/functions" to "1:/lib/functions". +COMPILE "0:/lib/guidance" to "1:/lib/guidance". SET core:bootfilename to "noop". diff --git a/launch.ks b/launch.ks index a4f830c..67d7d70 100644 --- a/launch.ks +++ b/launch.ks @@ -1,4 +1,4 @@ -run once "lib/functions". +run once "lib/guidance". local APOAPSIS_TARGET is 80000. local GRAVITY_TURN_START is 5000. @@ -23,23 +23,27 @@ when TWR() > 1.5 then { return false. } - lock THROTTLE to ThrottleToTWR(1.5). + local newThrot is ThrottleToTWR(1.5). + print "Setting throttle to " + newThrot. + lock THROTTLE to newThrot. return true. } // Main ascent control. lock THROTTLE to 1.0. -lock STEERING to UP. +lock STEERING to heading(90,90,-90). stage. wait until SHIP:ALTITUDE > 200. -lock STEERING to heading(90, 85, 90). +lock STEERING to heading(90, 85, -90). wait until SHIP:ALTITUDE > GRAVITY_TURN_START. +print "Beginning gravity turn". until SHIP:APOAPSIS > 80000 { - local angle is min(30, SHIP:PROGRADE:PITCH - 2). - lock STEERING to heading(90, angle, 90). + local angle is max(30, SHIP:PROGRADE:PITCH - 2). + lock STEERING to heading(90, angle, -90). wait 0.001. } +print "Releasing controls. Good luck, Kerman!". set THROTTLE to 0.0. diff --git a/lib/guidance.ks b/lib/guidance.ks index 6634c4a..d7fbb44 100644 --- a/lib/guidance.ks +++ b/lib/guidance.ks @@ -1,16 +1,17 @@ +// Functions for calculating navigational and guidance values. @lazyglobal off. // Returns the throttle value you should use to achieve the // target TWR. If TWR can't be achieved, returns 1.0. (full throttle) function ThrottleToTWR { - parameter twr is 1.5. + parameter targetTWR is 1.5. local m is SHIP:MASS. local g is 9.81. if HAS_GRAV_SENSOR = true { set g to SHIP:SENSORS:GRAV:MAG. } - return min((twr*m*g)/SHIP:AVAILABLETHRUST, 1.0). + return min((targetTWR*m*g)/SHIP:AVAILABLETHRUST, 1.0). } // Calculates the ship's current TWR.