flight/pid,sensors/gyro: D-term pre-diff LPF + code quality improvements#11465
Open
19379353560 wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
Open
flight/pid,sensors/gyro: D-term pre-diff LPF + code quality improvements#1146519379353560 wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
19379353560 wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
Conversation
added 2 commits
March 31, 2026 01:43
- dTermProcess: early return when kD==0, remove redundant variable - pidInitFilters: merge 3 init loops into 1, extract common US2S(refreshRate) subexpression - pidApplyMulticopterRateController: factor out antiWindupScaler*dT from I-term update - gyroFilter: rename preLulu to preFilterGyro, add const - pidApplyFixedWingRateController/pidApplyMulticopterRateController: add const to itermLimit No behavior change. All modifications are structural/readability improvements.
…ments Pre-differentiation LPF (v1, from master): - pid.h: add dterm_lpf2_hz field to pidProfile_t - pid.c: add dtermLpf2State and previousFilteredGyroRate to pidState_t - pid.c: initialize pre-diff filter in pidInitFilters() - pid.c: apply pre-diff filter in dTermProcess() before differentiation - settings.yaml: add dterm_lpf2_hz parameter (default 250Hz, range 0-500) Code quality improvements (v2): - dTermProcess: early return when kD==0, remove redundant newDTerm variable - pidInitFilters: merge 3 axis loops into 1, extract common dT subexpression - pidApplyMulticopterRateController: factor out antiWindupScaler*dT - Add const to itermLimit in both FW and MC rate controllers - gyroFilter: rename preLulu to preFilterGyro, add const Noise reduction: diff amplification ~9x -> ~3.6x, latency +0.6ms at 1kHz.
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.
Summary
Combines the D-term pre-differentiation LPF optimization with follow-up code quality improvements.
Part 1: D-term pre-differentiation LPF
Filters gyro before differentiation instead of after, reducing noise amplification.
Files changed:
pid.h: adddterm_lpf2_hztopidProfile_tpid.c: adddtermLpf2State/previousFilteredGyroRatetopidState_t, initialize and apply inpidInitFilters()/dTermProcess()settings.yaml: adddterm_lpf2_hzparameter (default 250Hz, range 0–500)Part 2: Code quality improvements
dTermProcess: early return whenkD==0, remove redundantnewDTermvariablepidInitFilters: merge 3 separate axis loops into 1, extractconst float dT = US2S(refreshRate)pidApplyMulticopterRateController: factor outantiWindupScaler*dTfrom I-term updateconsttoitermLimitin both FW and MC rate controllersgyroFilter: renamepreLulu→preFilterGyro, addconstTest plan
make check