Improvements to auto-launch script, inspired partially by the discussion at https://amyparent.com/blog/automating-rocket-launches.html

This commit is contained in:
Anna Rose 2021-08-20 21:20:15 -04:00
parent aa59db4f82
commit 18f7e996a7
2 changed files with 29 additions and 22 deletions

View File

@ -24,10 +24,10 @@ function getPitch {
function Launch {
parameter apoapsisTarget is 80000.
parameter atmoTWR is 1.8.
parameter gravityTurnStart is 8000.
parameter leadAngle is 5.
parameter atmoTWR is 2.0.
parameter leadAngle is 2.
parameter minPitch is 5.
parameter initialPitch is 10.
parameter autoStage is true.
// Configure subsystems.
@ -53,33 +53,40 @@ function Launch {
}
}
// Hold throttle to maintain target TWR.
// We do *not* use a PID Loop here because we can
// calculate the correct value discretely.
// Drag controls
when SHIP:VERTICALSPEED > 340 then {
print "Throttling for drag control.".
lock THROTTLE to ThrottleToTWR(atmoTWR).
print "Throttling to maintain a TWR of " + atmoTWR.
// 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.
when SHIP:ALTITUDE > 32000 then {
lock THROTTLE to 1.0.
}
}
// Main ascent control.
print "Phase 1: Vertical Ascent.".
lock THROTTLE to 1.0.
lock STEERING to Heading(90,90,270).
stage.
wait until SHIP:VERTICALSPEED > 100.
wait until SHIP:ALTITUDE > gravityTurnStart.
print "Turning gravity...".
print "Phase 2: Initial Pitch.".
lock STEERING to getAscentDir(leadAngle, minPitch).
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 getPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= 90-initialPitch.
lock THROTTLE to 1.0.
print "Phase 3: Stable Prograde Boost.".
lock STEERING to getAscentDir(0, minPitch).
wait until SHIP:ORBIT:APOAPSIS > apoapsisTarget.
// TODO: A smoother approach based on target orbital velocity should be considered.
print "Phase 4: Circularization Maneuver.".
lock THROTTLE to 0.0.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
wait 0.001. // make sure these control updates get applied
print "Target apoapsis acquired. Creating maneuver node.".
add CreateCircularizationNode().
ExecNode().
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
print "Ascent Complete.".
unlock THROTTLE.
unlock STEERING.
SAS on.

View File

@ -93,9 +93,9 @@ MakeMenu(
MakeButton(rows[2], "LNCH"),
List(
List("Target Apoapsis", "SCALAR", "80000"),
List("Atmo TWR", "SCALAR", "1.8"),
List("Gravity Turn Alt", "SCALAR", "8000"),
List("Lead Angle", "SCALAR", "5"),
List("Initial Pitch", "SCALAR", "20"),
List("Lead Angle", "SCALAR", "2"),
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["Gravity Turn Alt"]:TEXT:ToNumber(),
options["Lead Angle"]:TEXT:ToNumber(),
options["Minimum Pitch"]:TEXT:ToNumber(),
options["Initial Pitch"]:TEXT:ToNumber(),
options["Autostage"]:PRESSED
).
}