flight/pid: add D-term pre-differentiation LPF (dterm_lpf2_hz)#11464
flight/pid: add D-term pre-differentiation LPF (dterm_lpf2_hz)#1146419379353560 wants to merge 4 commits intoiNavFlight:maintenance-9.xfrom
Conversation
Maintenance 9.x to master
Updated instructions to reflect the use of the maintenance branch instead of master for cloning and merging.
…ch-7 Update branch references from master to maintenance
Differentiation amplifies high-frequency noise by f_loop/f_cutoff (~9x at 1kHz loop). Add an optional PT1 pre-filter applied before differentiation to reduce this amplification to ~3.6x, at the cost of only +0.6ms latency at the default 250Hz cutoff. This is inspired by Betaflight's architecture where gyro data is filtered before the derivative is computed. New parameter: dterm_lpf2_hz (default 250, 0 = disabled) - 5-inch builds: 250Hz recommended - 7-inch builds: 200Hz recommended Benefits: - D gain headroom increases ~15-25% - Improved propwash rejection - Better altitude/position hold disturbance rejection The added latency is negligible for the position/altitude loop (bandwidth <5Hz). Backward compatible: set dterm_lpf2_hz=0 to restore stock behavior. Closes: iNavFlight#11463
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
|
Hi, just wanted to kindly ping this PR for review. The CI checks are passing and the implementation is ready. Would appreciate any feedback or review from the maintainers when you have a chance. Thanks! |
Problem
In the current multirotor PID controller, differentiation is applied directly to the raw gyro signal:
Differentiation amplifies high-frequency noise by
f_loop / f_cutoff. At 1 kHz loop rate this is roughly 9×. The downstream PT2 then has to suppress that amplified noise, which limits how high D gain can be set before oscillation occurs.Solution
Add an optional PT1 pre-filter applied before differentiation:
This reduces noise amplification from ~9× to ~3.6× at the cost of only +0.6 ms latency (PT1 @ 250 Hz, 1 kHz loop).
Changes
pidState_t: adddtermLpf2State(PT1) andpreviousFilteredGyroRatedTermProcess(): pre-filter path activated whendterm_lpf2_hz > 0pidInitFilters(): initialize pre-diff filter from configpidProfile_t: adddterm_lpf2_hzfieldsettings.yaml: newdterm_lpf2_hzparameter (default 250 Hz, 0 = disabled)Impact
The added latency is negligible for the position/altitude loop (bandwidth < 5 Hz). Setting
dterm_lpf2_hz = 0restores stock behavior exactly.Recommended values
dterm_lpf2_hz = 250dterm_lpf2_hz = 200Related discussion: #11463