Repository navigation
fix: make the PID return to auto mode exact with an integral term - #22
Merged
Merged
Conversation
The auto-mode bias omitted the integral step that the next compute adds, so with a nonzero ki the first auto output was one step away from the held output. The bias now subtracts that step, saturating instead of overflowing the accumulator, and entering manual mode clears the derivative term so a return without a manual step is exact too. Refs #21
4 tasks done
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.
Layer 1 of 1. The d_filter_alpha fix merged separately as #20.
What and why
fpc_pid_set_mode(..., FPC_PID_MODE_AUTO, ...)setI = u − kp·e − D, but the nextfpc_pid_computeaddski·dt·ebefore forming its output. So for an unchanged error and a nonzeroki, the first auto output wasu + ki·dt·e, while the header promisesu.I = u − kp·e − ki·dt·e, clamped to the integral bounds as before.kp,ki·dtand error get close to 2^63. The newfpc_pid_msub_satsaturates the second subtraction toFXP_WIDE_MAX/FXP_WIDE_MIN. Either value lies beyond the integral bounds, so the clamp lands on the right bound and returnsFPC_STATUS_SATURATED. The overflow-bound comment inpid_controller.canddocs/design.mdcovers this.Dwas zeroed only by a manualcomputestep. A manual-then-auto switch with no step in between leftDin place, and the next step moved it, so the output still bumped. Entering manual mode now clearsD, which drops it from the bias and makes the existingdocs/api.mdstatement, "the derivative term stays 0", true from entry.Acceptance criteria
ki ≠ 0.test_bumpless_return_with_integralchecks the draft's case (kp1,ki0.5, held 300, error 100 → 300, integral 150) for both error signs.ki ≠ 0fails on the current code and passes after the fix. On master the test fails atstate.integral == 150(it is 200).test_bumpless_return_without_manual_stepfails without theDreset.test_bumpless_rebias_saturatesdrives both saturation branches with full-scale gains and errors, and runs clean under UBSan.docs/api.mdanddocs/design.mddescribe exact transfer, which is exact unless the bias was clamped.Checks
meson testunder ASan and UBSan: 2/2. The coverage gate is 100% of lines (274) and branches (144).misch run --baseline,misch deviations,scripts/format.sh.-Dwerror=true: all build.Refs #21