Skip to content

Fixed wing nav: reset WP cross-track tracking state on re-engagement#11640

Open
b14ckyy wants to merge 1 commit into
iNavFlight:release/9.1from
b14ckyy:fix/fw-wp-tracking-state-reset
Open

Fixed wing nav: reset WP cross-track tracking state on re-engagement#11640
b14ckyy wants to merge 1 commit into
iNavFlight:release/9.1from
b14ckyy:fix/fw-wp-tracking-state-reset

Conversation

@b14ckyy

@b14ckyy b14ckyy commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes a brief, unnecessary heading twitch when a fixed-wing aircraft rejoins a
waypoint course line after a turn or loiter, with nav_fw_wp_tracking_accuracy
(waypoint course tracking) enabled.

Root cause

The cross-track controller in updatePositionHeadingController_FW() keeps its
rate/error state in function-local static variables (previousCrossTrackError,
previousCrossTrackErrorUpdateTime, crossTrackErrorRate and the rate filter)
that are never reset.

While the controller is disengaged — during a turn/loiter
(needToCalculateCircularLoiter) or when the feature is off — that state freezes.
On the next leg the first control sample is then computed against stale cross-track
data from the previous leg, producing a small heading kick as the aircraft
rejoins the new course line.

Fix

Re-seed the controller state to the current cross-track error whenever it is not
actively steering, so on re-engagement the error delta starts near zero and the
rate filter starts clean.

  • Moved the four state variables up one scope (still static) so the inactive
    branch can reset them.
  • Added an else branch that syncs previousCrossTrackError/timestamp to the
    current value, zeroes the rate, and resets the rate filter.

No new settings, no parameter-group change, no MSP/protocol change. No behavioural
change when nav_fw_wp_tracking_accuracy = 0.

Target branch

maintenance-9.x — backward-compatible bug fix per the branching guidelines.
Propagates to maintenance-10.x via the normal merge-forward flow.

Testing

  • Builds cleanly (MATEKF722SE / F7); change is platform-independent C.
  • In-flight verification on a WP mission with nav_fw_wp_tracking_accuracy
    enabled, checking clean leg re-capture after turns/loiter.

Scope

Single focused fix in navigation/navigation_fixedwing.c (~14 added / 5 removed).

@b14ckyy b14ckyy added this to the 9.1 milestone Jun 9, 2026
@b14ckyy b14ckyy added the Bugfix label Jun 9, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Test firmware build ready — commit 9c40920

Download firmware for PR #11640

238 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

@b14ckyy b14ckyy changed the base branch from maintenance-9.x to release/9.1 June 9, 2026 11:37
The fixed-wing waypoint cross-track controller (nav_fw_wp_tracking_accuracy) kept
its rate/error state in function-local statics that were never reset. After a turn
or loiter, where the controller is disengaged (needToCalculateCircularLoiter), the
first sample on the next leg was computed from stale data from the previous leg,
causing a small heading twitch when rejoining the course line.

Re-seed the controller state to the current cross-track error while it is not
actively steering, so it re-engages cleanly on the next leg.
@b14ckyy b14ckyy force-pushed the fix/fw-wp-tracking-state-reset branch from 4022174 to 9c40920 Compare June 9, 2026 11:49
@b14ckyy b14ckyy requested a review from breadoven June 9, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant