Repository navigation
Rearchitect PSG's atmospheric flight phase - #2780
Draft
lamont-granquist wants to merge 8 commits into
Draft
lamont-granquist wants to merge 8 commits into
lamont-granquist wants to merge 8 commits into
Conversation
After liftoff the vertical ascent and the pitch program fly a fixed program, and the pitch program hands over to guidance where it meets the solution's pitch, so a re-solve from the climb would move that pitch. The optimizer now holds off until guidance takes over, and says so with two new OptimizerState values, VERTICAL_ASCENT and PITCH_PROGRAM. Without a solution yet the solves go on, or guidance would never take over. A solve still running at liftoff was started on the pad and is kept.
The PSG autopilot used to leave PRELAUNCH as soon as the countdown's prelaunch was done and then ask LaunchCountdown.HoldForLiftoff every tick, which reached back into PSG (WaitingForGuidance) to find out whether there was a Solution. The AscentStateMachine now stays in PRELAUNCH on the ground while the countdown is running or there is no Solution, with the throttle off and the attitude axes let go (AscentAttitude.OFF). The countdown's prelaunch is only driven until it is done. Off the ground nothing is cut, since a one-tick throttle cut could cost a RealFuels engine its ignition. A Solution dropped on the pad by a new countdown sends VERTICAL_ASCENT back to PRELAUNCH, and the prelaunch runs again. The countdown no longer knows about PSG: the autopilot holds T-0 with SetLaunchHold until its prelaunch is done and it has a Solution. HoldForLiftoff and WaitingForGuidance are gone, and the classic autopilot inlines its own wait for T-0. CheckLiftoffHold and AllowThrottle are replaced by a CountdownActive input. GUIDANCESTATUS reads INITIALIZED in PRELAUNCH with a Solution.
Guidance flies straight up at full throttle to the pitch start height before the pitch program, but on the ground PSG solved from the pad itself. On the ground the PSG simulation now asks the AscentBuilder for a VerticalRise of the height left to climb. The rise is integrated ahead of the solve with the optimizer's own full throttle dynamics (AscentProblem.FullThrottleAcceleration, shared with the guesser), and the Problem starts at its top. The first phase starts there with the propellant the rise left it, and every burn's VexCurrent moves to the density at the top so the thrust stays the same at every height. With a first phase that coasts, a thrust-to-weight under 1, or a stage that burns out before the top, the solve runs from the pad as before. The rise is not a Phase, since the optimizer, its warm start and guidance's phase indices all start at the first phase. The Problem carries it (Problem.Rise) and each Solution keeps its own copy in front of its phases, from TStart on the ground to T0. Only the queries by time see it: R, V, U, M, StateVectors, DV, Vgo, and the time and delta-v left in the first phase, which burns it. It goes with DeepCopy, DeNormalized and RotateToLaunchSite, which still turns about the pad. The warm start reads the old Solution from its T0 on, so it never reads the rise. The rise is presolved whenever the vessel is on the ground, not only at MET zero, so a launch from the surface of a moon gets it too. What used to be T0 <= 0 is now Solution.FromPad (TStart <= 0), which still decides the rotation to the launch site and the PadSolution, and Problem.PadStart starts the guesser's guess vertically. VERTICAL_ASCENT flies full throttle with a rise, as it was planned. SolutionTrace samples the rise first as phase -1 and has a PhaseCount for the graph's status line, and the map trajectory starts at TStart.
A problem on the ground now starts at the top of the vertical rise,
which VerticalRise presolves, and the optimizer is held off through
the real vertical ascent and pitch program. The guesser's own climb
to 50 m/s vertical speed was a second climb on top of the rise that
guidance never flies.
Mode.VERTICAL, V_KICK and the kick event are gone. A ground start
(Problem.PadStart) kicks over at once: the pitchover into a gravity
turn in an atmosphere, linear tangent steering from the 45 degrees up
seed in vacuum. An in-flight start is unchanged.
AscentGuesserTests guess the Titan II, The Standard and the Mainsail
TinCan from the top of a 100 m rise and check that the guess is off
the vertical just after the top.
Known issues, 8 PSG tests fail:
Atmospheric pad fixtures that solve from the pad without a
VerticalRise now kick over from a standstill, and the guess's gravity
turn tips over before it has any speed:
AscentGuesserTests.TheStandardAtmosphere falls back (TWR 1.44)
TheStandardTests.TheStandardPeriapsis falls back (TWR 1.44)
TheStandardTests.TheStandardPeriapsisUpperStageShutdown
falls back (TWR 1.44)
RealRocketTests.Falcon9ExpendableGeoStationary falls back (TWR 1.40)
RealRocketTests.Delta3GeoSynchronous guesser SQP -8
BuggyTests.FourStagesNeedsTwo guesser SQP -8
Either these fixtures need a VerticalRise like the PSG simulation
uses, or the guess needs a pitchover that holds up from low speed.
The same failure can show up in flight with a short pitch start
height or a low thrust-to-weight.
Two VerticalRiseTests also fail:
TinCanRisesStraightUpFromThePad the 1e-12 R/V/M continuity check
is off by about 1e-10, too tight
TinCanRiseRoundTrips the warm start takes 6 iterations
against a bound of 5, since the
cold guess changed
AscentBuilder.VerticalRise is opt-in, and only the PSG simulation called it, so the pad fixtures solved from the pad itself, a start the game never makes. They passed only while the guesser climbed straight up on its own. Every fixture that starts on the pad now rises 100 m, the default pitch start height, before it solves. The in-flight re-solve in Titan2Tests and InputValidationTests, which never solve, are left without one, and SolutionTests.TinCanBuilder takes a rise that is 0 for its solve in flight. The assertions that meant liftoff now say so: the pinned steering is checked at the top of the rise (T0), where guidance takes over, since the solution points straight up at the pad. Phase time-to-go is measured from TStart, which counts the rise in the first phase, so the Titan II booster still burns 156 s, and the delta-v shortfall compares with Vgo from TStart. The rise costs the vacuum fixtures 30 to 64 m/s of Vgo, within its own gravity loss of about 45 to 67 m/s: they have no planetary rotation in their dynamics, and their optimum pitches over about 40 degrees right off the pad. The fixed burn time fixtures reach orbits 105 to 126 km lower in semi-major axis. The atmospheric fixtures barely move, since their optimum left the pad nearly vertical anyway. AscentGuesserTests guess every pad problem from the top of the rise, and TooHeavyToLiftOffGivesTheThrustToWeight checks it gets no rise. This fixes the 8 failures left by de26931. The TinCan warm start from a cold start stops at a primal feasibility of 5e-8 with the rise, so the warm start from it takes 6 iterations to tighten it and lands on the same trajectory: TinCanRiseRoundTrips and WarmStartFromATurnedLaunchSite allow up to 10. The continuity check between the rise and the first phase is 1e-9.
Contributor
✅ Build Artifact 🚀MechJeb2-b6434fe.zip (built from a348480) |
The PSG simulation handed every converged solve to the autopilot, whatever state the autopilot had reached while the solve ran. Only AscentStateMachine.SetSolution refused one, and only in terminal guidance and once finished. A solve started on the pad that converged after liftoff, or one that converged during a jettison, still reached guidance. A solution is now handed off only while the autopilot is in PRELAUNCH, BURNING or COASTING (TakesSolution). In any other state it is thrown away and logged, and none of the success bookkeeping runs: the warm start, the reach check, VacuumCoastSolved, the converge count and the staleness all stay as they were. This replaces the rule from 903a021 that a solve still running at liftoff is kept. Ascents engaged in flight aren't supported, so the vertical ascent and the pitch program always have the pad solution and need no exception for a first one.
2be3843 throws away a solve that converges in any other state, so the PSG simulation no longer starts one there either. The same TakesSolution gate now comes right after the stages are reconciled, and PausedState says why the optimizer waits: VERTICAL_ASCENT ON_PAD from T-0 until the clamps let go, then VERTICAL_ASCENT PITCH_PROGRAM PITCH_PROGRAM JETTISON JETTISON (new): "paused for the jettison, resumes in the burn" TERMINAL(_RCS) TERMINAL FINISHED FINISHED It replaces the separate checks for terminal guidance and the end, the TERMINAL and FINISHED cases of the "only unguided stages left" state, and the pause for the vertical ascent and the pitch program. That pause kept solving without a Solution, for an ascent engaged in flight, which isn't supported: every launch starts in PRELAUNCH on the ground and has its Solution before the vertical ascent. TerminalStarted and GuidanceFinished still cancel a running solve, to free the worker sooner. CoastStarted and CoastEnded are still needed, since COASTING takes solutions.
A Solution solved before a jettison cut could land while JETTISON waited for KSP's staging cooldown. If it ended the burn later than the one being cut, guidance went back to BURNING and throttled the cut engines up again (#2782). 8b173b5a kept the PSG simulation from handing such a Solution over, but the state machine still took one. AscentStateMachine.TakesSolution is now the rule: PRELAUNCH, BURNING and COASTING. SetSolution refuses a Solution in any other state, which extends its old refusal in terminal guidance and once finished. The vertical ascent and the pitch program fly the pad Solution to guidance, a jettison drops the burn its Solution cut, and terminal guidance flies to the end of the Solution it started with. The PSG autopilot passes TakesSolution through, and its SetSolution returns whether the Solution was taken. The simulation drops its own copy of the rule: HandleDoneTask throws away a Solution SetSolution refused, before any of its bookkeeping, and solves start only while the autopilot TakesSolution. The autopilot's IsTerminal, which nothing used any more, is gone. JettisonRefusesALateSolution is the scenario from #2782 (it lit the cut booster twice before this). ClimbRefusesALateSolution replaces PitchProgramMeetsTheGuidanceOfANewSolutionAtOnce, which gave an ascent engaged in flight its first Solution in the pitch program. Ascents engaged in flight aren't supported, and the pitch program now refuses that Solution: the new test checks the refusal in the vertical ascent and the pitch program of a pad launch, which keeps its pad Solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To start with this presolves for a vertical rise off the pad.
The next step is probably a major refactor of the Ascent algorithm and Optimizer to:
As at least a first cut, the Qalpha and MaxQ constraints should get removed from the optimizer, maxQ throttle down will just be a dispersion
The bigger problem to solve is modelling ZLGT through arbitrary vehicle configurations and phases, with one split-phase where the handoff happens to isolate the kink in the trajectory, which will require some kind of iterative solve to find the correct phase (perhaps using a hint from the AscentGuesser when that is stable).
This won't quite solve all the worlds problems, but is much more like how real rockets really fly, and should solve fast and can be stabilized.