diff --git a/lib/launch_rocket.ks b/lib/launch_rocket.ks index 885eb18..10ecfd6 100644 --- a/lib/launch_rocket.ks +++ b/lib/launch_rocket.ks @@ -28,6 +28,7 @@ function Launch { parameter LEAD_ANGLE is 5. // parameter INITIAL_PITCH is 85. parameter MINIMUM_PITCH is 5. + parameter AUTOSTAGE is true. // Configure subsystems. RCS off. @@ -42,12 +43,14 @@ function Launch { // staging logic. Stage as many times as needed until we finish ascent. // Once Apo target is attained just drop this trigger. - when FlameOut() or SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET then { - if SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET { - return false. + if AUTOSTAGE { + when FlameOut() or SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET then { + if SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET { + return false. + } + stage. + return true. } - stage. - return true. } // Hold throttle to maintain target TWR. diff --git a/lib/stabilize_rocket.ks b/lib/stabilize_rocket.ks index 62953fd..fcd62a1 100644 --- a/lib/stabilize_rocket.ks +++ b/lib/stabilize_rocket.ks @@ -13,6 +13,10 @@ function Land { assumeControl(). alignForHover(). + if done { + restoreControl(). + return. + } local pid is PIDLoop(0.1, 0.01, 0.01, 0, 1). lock THROTTLE to pid:Update(TIME:SECONDS, SHIP:VERTICALSPEED). @@ -34,6 +38,10 @@ function Hover { assumeControl(). alignForHover(). + if done { + restoreControl(). + return. + } local throttlePID is PIDLoop(0.1, 0.1, 0.001, 0, 1). set throttlePID:SETPOINT to vertSpeed. lock THROTTLE to throttlePID:Update(TIME:SECONDS, SHIP:VERTICALSPEED). @@ -43,24 +51,30 @@ function Hover { restoreControl(). } +function hoverVectorVac { + parameter top. + if SHIP:VERTICALSPEED > 0 { + return SHIP:UP. + } + return LookDirUp(SHIP:SRFRETROGRADE:FOREVECTOR, top). +} + function alignForHover { - set cRot to SHIP:FACING:FOREVECTOR. + set top to SHIP:FACING:FOREVECTOR. if ReadSensor("PRES") = 0 { // if we're in a vacuum, align with retrograde for smoother horizontal control. - lock STEERING to LookDirUp(SHIP:SRFRETROGRADE:FOREVECTOR, cRot). + lock STEERING to hoverDirVac(top). print "Aligning with retrograde.". - wait until done or VAng(SHIP:FACING:FOREVECTOR, SHIP:SRFRETROGRADE:FOREVECTOR) < 1. + wait until done or VAng(SHIP:FACING:FOREVECTOR, hoverDirVac():FOREVECTOR) < 1. if done { - restoreControl(). return. } } else { // ... otherwise just align vertically. - lock STEERING to LookDirUp(SHIP:UP:FOREVECTOR, cRot). + lock STEERING to LookDirUp(SHIP:UP:FOREVECTOR, top). print "Aligning vertical.". wait until done or VAng(SHIP:FACING:FOREVECTOR, SHIP:UP:FOREVECTOR) < 1. if done { - restoreControl(). return. } } diff --git a/prog/rocket.ks b/prog/rocket.ks index a692d06..41f3d3d 100644 --- a/prog/rocket.ks +++ b/prog/rocket.ks @@ -82,7 +82,8 @@ MakeMenu( List("Atmo TWR", "SCALAR", "1.8"), List("Gravity Turn Alt", "SCALAR", "8000"), List("Lead Angle", "SCALAR", "5"), - List("Minimum Pitch", "SCALAR", "5") + List("Minimum Pitch", "SCALAR", "5"), + List("Autostage", "BOOL", true) ), "Execute", { @@ -92,7 +93,8 @@ MakeMenu( options["Atmo TWR"]:TEXT:ToNumber(), options["Gravity Turn Alt"]:TEXT:ToNumber(), options["Lead Angle"]:TEXT:ToNumber(), - options["Minimum Pitch"]:TEXT:ToNumber() + options["Minimum Pitch"]:TEXT:ToNumber(), + options["Autostage"]:PRESSED ). } ).