flight/pid,sensors/gyro: D-term pre-diff LPF + code quality improvements#11465
flight/pid,sensors/gyro: D-term pre-diff LPF + code quality improvements#1146519379353560 wants to merge 3 commits intoiNavFlight:maintenance-9.xfrom
Conversation
- 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.
|
Hi, just wanted to kindly ping this PR for review. This builds on the D-term pre-differentiation LPF work in #11464 with additional code quality improvements. Would appreciate any feedback from the maintainers when you have a chance. Thanks! |
|
Test firmware build ready — commit Download firmware for PR #11465 228 targets built. Find your board's
|
|
Thanks for this. One thing in the code that I wonder about. previousFilteredGyroRate is not reset on filter re-init — if pidInitFilters() is called with the feature transitioning from disabled→enabled (such as a VTOL mid-flight profile change), the stale zero causes a short D-term spike scaled by kD × dT_inv × gyroRate. At 1kHz that multiplier is 1000 — potentially significant. Then we need some folks to flight test it. I think the default post filter is 110 Hz, doubling the filter frequency may have other effects different from the core of this change, right? Speaking of the default, would it make sense to SETTING_DTERM_LPF2_HZ_DEFAULT rather than hard-coding 250, so that settings.yaml is the single source of truth? But we'd probably default it to zero (disabled), at least for a release cycle. |
d0bacbe to
bdc2d95
Compare
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