Skip to content

fix(ekf2): hard reset external position estimate while position aiding active#27856

Open
haumarco wants to merge 1 commit into
mainfrom
restrict_external_pos_reset
Open

fix(ekf2): hard reset external position estimate while position aiding active#27856
haumarco wants to merge 1 commit into
mainfrom
restrict_external_pos_reset

Conversation

@haumarco

Copy link
Copy Markdown
Contributor

Solved Problem

Since #25223, MAV_CMD_EXTERNAL_POSITION_ESTIMATE is also executed while a horizontal position source (GNSS, EV, AGP, beacon) is being fused. In that case the command takes the reset-by-fusion path introduced in #25885, which applies the innovation with an artificially high Kalman gain and deliberately pushes it into the correlated states.

This is correct during dead reckoning (large position variance, innovation reflects accumulated state error), but harmful with an active position source: the position variance is small, so the gain into correlated states is large, and the innovation is typically caused by a bias of the aiding source rather than by state error. In a real flight this yanked the velocity state by ~18 m/s from an 83 m position innovation, which then caused airspeed and position fusion to be gate-rejected.

Solution

Route the command to the hard-reset branch whenever isHorizontalPositionAidingActive() is true. The hard reset translates the position, keeps velocity (minus wind), and zeroes wind with inflated variance. Reset-by-fusion remains in place for its intended dead-reckoning use case.

Changelog Entry

For release notes:

Bugfix: MAV_CMD_EXTERNAL_POSITION_ESTIMATE now performs a hard position reset instead of reset-by-fusion while a horizontal position aiding source (GNSS, EV, AGP, beacon) is active, preventing large velocity/wind/heading corruption from the forced fusion

Test coverage

Tested in SITL

@haumarco haumarco requested a review from bresch July 10, 2026 06:54
@github-actions github-actions Bot added kind:bug Something is broken or behaving incorrectly. scope:estimation EKF, local position, attitude, wind, bias, or aiding logic. labels Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 32 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  +0.0%     +32    .text
    +2.1%     +28  +2.1%     +28    Ekf::resetGlobalPosToExternalObservation()
    +0.2%      +4  +0.2%      +4    Ekf::fuseMag()
  +0.0%     +55  [ = ]       0    .debug_abbrev
  +0.0%     +92  [ = ]       0    .debug_info
  +0.0%     +53  [ = ]       0    .debug_line
     +50%      +1  [ = ]       0    [Unmapped]
    +0.0%     +52  [ = ]       0    [section .debug_line]
  +0.0%     +78  [ = ]       0    .debug_loclists
  +0.0%      +2  [ = ]       0    .debug_rnglists
    [NEW]      +1  [ = ]       0    [Unmapped]
    +0.0%      +1  [ = ]       0    [section .debug_rnglists]
  -0.4%     -32  [ = ]       0    [Unmapped]
  +0.0%    +280  +0.0%     +32    TOTAL

px4_fmu-v6x [Total VM Diff: 32 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  +0.0%     +32    .text
    +2.1%     +28  +2.1%     +28    Ekf::resetGlobalPosToExternalObservation()
    +0.2%      +4  +0.2%      +4    Ekf::fuseMag()
  +0.0%     +55  [ = ]       0    .debug_abbrev
  +0.0%     +92  [ = ]       0    .debug_info
  +0.0%     +53  [ = ]       0    .debug_line
   -50.0%      -3  [ = ]       0    [Unmapped]
    +0.0%     +56  [ = ]       0    [section .debug_line]
  +0.0%     +20  [ = ]       0    .debug_loclists
  -0.6%     -32  [ = ]       0    [Unmapped]
  +0.0%    +220  +0.0%     +32    TOTAL

Updated: 2026-07-10T07:00:40

@bresch bresch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So external pos aiding becomes external pos reset if another source of position is active; si it gets the absolute priority over everything else. I guess that's fin as long as we only use it for manual position updates (i.e.: only a couple of updates, not an external sensor with a constant update rate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug Something is broken or behaving incorrectly. scope:estimation EKF, local position, attitude, wind, bias, or aiding logic.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants