Skip to content

BetterController: gain-schedule Kp against maxAlpha#2113

Open
Alex6511 wants to merge 1 commit intoMuMech:devfrom
Alex6511:bettercontroller-kp-scheduling
Open

BetterController: gain-schedule Kp against maxAlpha#2113
Alex6511 wants to merge 1 commit intoMuMech:devfrom
Alex6511:bettercontroller-kp-scheduling

Conversation

@Alex6511
Copy link
Copy Markdown

@Alex6511 Alex6511 commented Apr 8, 2026

No description provided.

Recent BetterController tuning (d65f0e9, 2025-12-02) raised the combined
Kp_pos * Kp_vel product from ~8.5 to ~16.2, optimized against stock vessels
with healthy gimbal authority. On RP-1 upper stages with weak vacuum-engine
gimbals (maxAlpha ~0.3 rad/s^2), the velocity loop saturates on small
tracking errors (>~0.02 rad), and combined with the ~60ms gimbal actuator
lag this produces a structural limit cycle regardless of the cascade's
bang-bang vs PID branch.

Commit d65f0e9's message acknowledges the trade-off: "probably close to
ideal performance without gain scheduling based on the gimbal response
rate". This patch adds that scheduling.

Formula (per axis, inside UpdatePredictionPI):

    kpScaleBase = Clamp(_maxAlpha[i] / KpScaleRef, KpScaleMin, 1.0)
    kpScale     = sqrt(kpScaleBase)
    posKp_eff   = (PosKp / warpFactor) * kpScale
    velKp_eff   = VelKp * kpScale

The sqrt distributes the combined-gain reduction equally across both PID
loops, preserving the inner/outer cascade bandwidth separation ratio. At
kpScaleBase = 0.25 (the new KpScaleMin default), each loop is scaled by
0.5, producing a combined-gain factor of 0.25 that matches a hand-tuned
working configuration for Titan-class upper stages (Pos Kp=1.01, Vel
Kp=4.0, roughly half of the current defaults). For strong-actuator stages
where maxAlpha >= KpScaleRef, kpScale = 1.0 and the user's configured
gains apply unmodified.

New runtime-tunable fields (persistent, GUI-exposed alongside Soften):

- KpScaleRef (default 1.0 rad/s^2): the maxAlpha value at which the user's
  configured gains apply unmodified. Below this, both loops scale down.
- KpScaleMin (default 0.25): lower bound on kpScaleBase. Prevents
  pathological gain reduction on near-uncontrolled axes (roll with
  marginal control surface authority, etc).

Flight-tested on RP-1 Titan-1-Agena-1: RMS attitude error in the upper
stage burn drops from ~0.027 rad (sustained limit cycle) to ~0.00002 rad
(noise floor) using the scheduler defaults, matching the hand-tuned
reference configuration. Stage 6 (strong-gimbal sustainer) and stage 7
(booster) are unaffected by the scheduler within their normal maxAlpha
range. The two new GUI text fields ("Kp Scale Ref", "Kp Scale Min")
appear alongside the existing Soften tunable.

SETTINGS_VERSION bumped 16 -> 17 so existing user configs pick up the new
defaults via the OnModuleEnabled migration path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant