Fix #9912: Add I-term stability check to servo autotrim#11215
Open
sensei-hacker wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
Open
Fix #9912: Add I-term stability check to servo autotrim#11215sensei-hacker wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
sensei-hacker wants to merge 2 commits intoiNavFlight:maintenance-9.xfrom
Conversation
Prevent continuous servo autotrim from applying trim adjustments during maneuver transitions when I-term is changing rapidly due to transient error. Root Cause: The autotrim code verified all flight conditions (level attitude, centered sticks, low rotation rate) but failed to check that the I-term was in a steady state before transferring it to servo trim. During maneuver transitions (e.g., exiting a turn), I-term accumulates transient error. When the plane momentarily satisfies all level-flight conditions, this transient I-term is incorrectly transferred to servo midpoints, causing the aircraft to fly out-of-trim. Changes: - Added I-term rate-of-change tracking in processContinuousServoAutotrim() - Added stability threshold check before applying autotrim - Added configurable parameter: servo_autotrim_iterm_rate_limit (default: 2) - Only transfers I-term to trim when rate of change is below threshold The fix ensures trim updates only occur during true steady-level flight, not during transient conditions following maneuvers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #9912 by adding I-term stability detection to the servo autotrim feature. The fix prevents transferring transient I-term values to servo trim during maneuver transitions by checking that the I-term rate of change is below a configurable threshold before applying trim adjustments.
Key Changes:
- Added
servo_autotrim_iterm_rate_limitconfiguration parameter to control maximum acceptable I-term rate of change - Implemented I-term rate-of-change calculation in the autotrim logic to detect transient vs. stable I-term values
- Updated documentation with the new setting
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main/flight/servos.h | Adds servo_autotrim_iterm_rate_limit field to servoConfig_t struct to store the new configuration parameter |
| src/main/flight/servos.c | Implements I-term stability check by tracking previous I-term values and calculating rate of change before applying autotrim |
| src/main/fc/settings.yaml | Defines the new servo_autotrim_iterm_rate_limit setting with default value of 2 units/sec and range 0-50 |
| docs/Settings.md | Documents the new servo_autotrim_iterm_rate_limit setting for end users |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Move I-term tracking outside stable flight check for accurate rate calculation - Move servo_autotrim_iterm_rate_limit to end of struct for EEPROM compatibility
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
Hopefully fixes #9912 - Continuous auto-trim active during maneuvers
Adds I-term stability detection to servo autotrim to prevent transferring transient I-term to servo trim during maneuver transitions.
Root Cause
The autotrim code verified all flight conditions (level attitude, centered sticks, low rotation rate) but failed to check that the I-term was in a steady state before transferring it to servo trim.
During maneuver transitions (e.g., exiting a turn), I-term accumulates transient error. When the plane momentarily satisfies all level-flight conditions, this transient I-term is incorrectly transferred to servo midpoints.
We want to transfer the I-term only when it's stable, not immediately when the pilot centers the sticks after a hard maneuver. How stable is "stable"? I don't know, so I added the temporary setting
servo_autotrim_iterm_rate_limitto for testing. I anticipate that after testing we'll know what a reasonable value is and won't need to add yet another user-facing facing.Testing
Note: This PR requires flight testing to validate the fix. The I-term stability threshold may need adjustment based on flight testing feedback.
Because this does introduce a new setting, an "erase all" and reload of the diff/dump would be needed.
If testers prefer, I could also just use 2 or 3 for testing, and skip the setting.
Related
Potentially Fixes #9912
@Yury-MonZon @ProfDrYoMan