From 15c479cd18155e43616fe2f41944885f3413a3d9 Mon Sep 17 00:00:00 2001 From: annabunches Date: Sat, 21 Aug 2021 01:46:53 -0400 Subject: [PATCH] Use a time-based approach for the pitch instead of just a lead angle and a prayer. --- lib/boot.ks | 1 + lib/launch_rocket.ks | 21 +++++++++++++++++---- prog/rocket.ks | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/boot.ks b/lib/boot.ks index 334ed68..cb0be86 100644 --- a/lib/boot.ks +++ b/lib/boot.ks @@ -53,6 +53,7 @@ function compileFile { if debug { CopyPath("0:" + src + ".ks", "1:" + dest + ".ks"). + return. } compile "0:" + src. diff --git a/lib/launch_rocket.ks b/lib/launch_rocket.ks index 60d3b1a..c742cb8 100644 --- a/lib/launch_rocket.ks +++ b/lib/launch_rocket.ks @@ -22,12 +22,24 @@ function getPitch { return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). } +// Given a target (end) pitch, a target duration, and a start time, +// returns the correct current heading. +function pitchProgram { + parameter endPitch, duration, startTime. + + // what percent through the duration are we? + local elapsedP is (TIME:SECONDS - startTime) / duration. + local p is endPitch * elapsedP. + return Heading(90, 90 - p, 270). +} + function Launch { parameter apoapsisTarget is 80000. parameter atmoTWR is 2.0. - parameter leadAngle is 2. + // parameter leadAngle is 2. parameter minPitch is 5. - parameter initialPitch is 10. + parameter initialPitch is 20. + parameter pitchTime is 30. parameter autoStage is true. // Configure subsystems. @@ -71,8 +83,9 @@ function Launch { wait until SHIP:VERTICALSPEED > 100. print "Phase 2: Initial Pitch.". - lock STEERING to getAscentDir(leadAngle, minPitch). - wait until getPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= 90-initialPitch. + local startTime is TIME:SECONDS. + lock STEERING to pitchProgram(initialPitch, pitchTime, startTime). + wait pitchTime. print "Phase 3: Stable Prograde Boost.". lock STEERING to getAscentDir(0, minPitch). diff --git a/prog/rocket.ks b/prog/rocket.ks index 02bec5d..fe006d8 100644 --- a/prog/rocket.ks +++ b/prog/rocket.ks @@ -94,7 +94,7 @@ MakeMenu( List( List("Target Apoapsis", "SCALAR", "80000"), List("Initial Pitch", "SCALAR", "20"), - List("Lead Angle", "SCALAR", "2"), + List("Pitch Time", "SCALAR", "45"), List("Atmo TWR", "SCALAR", "2.0"), List("Minimum Pitch", "SCALAR", "5"), List("Autostage", "BOOL", true) @@ -105,9 +105,9 @@ MakeMenu( Launch( options["Target Apoapsis"]:TEXT:ToNumber(), options["Atmo TWR"]:TEXT:ToNumber(), - options["Lead Angle"]:TEXT:ToNumber(), options["Minimum Pitch"]:TEXT:ToNumber(), options["Initial Pitch"]:TEXT:ToNumber(), + options["Pitch Time"]:TEXT:ToNumber(), options["Autostage"]:PRESSED ). }