flight/pid: add D-term pre-differentiation LPF (dterm_lpf2_hz)#11464
Open
19379353560 wants to merge 1 commit intoiNavFlight:masterfrom
Open
flight/pid: add D-term pre-differentiation LPF (dterm_lpf2_hz)#1146419379353560 wants to merge 1 commit intoiNavFlight:masterfrom
19379353560 wants to merge 1 commit intoiNavFlight:masterfrom
Conversation
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. |
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.
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