Skip to content

AP_NavEKF3: resetHeightDatum stricter early return#32915

Closed
gdavud wants to merge 1 commit into
ArduPilot:masterfrom
gdavud:EKF3-onGround-issue
Closed

AP_NavEKF3: resetHeightDatum stricter early return#32915
gdavud wants to merge 1 commit into
ArduPilot:masterfrom
gdavud:EKF3-onGround-issue

Conversation

@gdavud
Copy link
Copy Markdown

@gdavud gdavud commented Apr 26, 2026

Summary

Attempts to fix issue #32720 with altitude spikes on termination (or disarm). AP_NavEKF3 lib treats all disarmed states as definetly on-ground. During flight termination, the vehicle can be airborne while disarmed which can trigger a height origin reset, causing an altitude spike.

Classification & Testing (check all that apply and add your own)

  • [ x] Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • [ x] Logs available on request

Description

NavEKF3_core::detectFlight() marks NavEKF3_core::onGround as true, this allows NavEKF3_core::resetHeightDatum() to run which may update NavEKF3_core::ekfGpsRefHgt which in turn may update the vehicle's local_origin in NavEKF3_core::getPosD() causing discontinuity in vertical position.

Function resetHeightDatum() returns false immediately if onGround is false. During the untermination test, onGround is true when the vehicle terminates (even tho we are still airborne), which aligns with the spike from the original issue.

This pr prevents NavEKF3_core::resetHeightDatum from executing if vehicle is disarmed while airborne.
Untermination test running on this patch:
solution


Some logs that explain the original issue:

AT-0001.8: AP: Throttle disarmed
arduplane: posD=-52.596778, onGround=0, inFlight=1, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=1
arduplane: posD=-52.755922, onGround=1, inFlight=0, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=0
...
AT-0001.8: Waiting for disarm (0.00s so far of allowed 30.00)
...
AT-0001.8: DISARMED after 0.00 seconds (allowed=30.00)
AT-0001.8: Waiting for text : terminating due to gcs request
AT-0001.8:   statustext got=(Terminating due to GCS request) want=(Terminating due to GCS request)
AT-0001.8: Found expected text in collection: terminating due to gcs request
...
AT-0001.8: Sending COMMAND_INT to (1,1) (MAV_CMD_DO_FLIGHTTERMINATION=185) (p1=0.000000 p2=0.000000 p3=0.000000 p4=0.000000 p5=0 p6=0  p7=0.000000 f=5)
...
AT-0001.8: ACK received: COMMAND_ACK {command : 185, result : 0, progress : 0, result_param2 : 0, target_system : 250, target_component : 250} (0.000000s)
AT-0001.8: Waiting for DISARM
AT-0001.8: AP: Aborting termination due to GCS request
...
AT-0001.8: Waiting for disarm (0.00s so far of allowed 30.00)
arduplane: posD=-56.713185, onGround=1, inFlight=0, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=0
...
arduplane: posD=-56.213194, onGround=1, inFlight=0, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=0
arduplane: posD=-112.811547, onGround=1, inFlight=0, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=0
arduplane: posD=-108.178366, onGround=1, inFlight=0, highAirSpd=1, highGndSpd=1, largeHgtChange=1, motorsArmed=0
...

@gdavud gdavud force-pushed the EKF3-onGround-issue branch from be091bb to d3cb926 Compare May 3, 2026 16:07
@gdavud gdavud changed the title AP_NavEKF3: disarm and low airspeed required for onGround to be true AP_NavEKF3: onGround May 3, 2026
@gdavud gdavud force-pushed the EKF3-onGround-issue branch from d3cb926 to 5d3d6f7 Compare May 4, 2026 15:03
@gdavud gdavud changed the title AP_NavEKF3: onGround AP_NavEKF3: resetHeightDatum stricter early return May 4, 2026
@gdavud gdavud marked this pull request as ready for review May 4, 2026 15:09
@gdavud gdavud force-pushed the EKF3-onGround-issue branch from 5d3d6f7 to 3807180 Compare May 4, 2026 15:17
bool NavEKF3_core::resetHeightDatum(void)
{
if (activeHgtSource == AP_NavEKF_Source::SourceZ::RANGEFINDER || !onGround) {
if (activeHgtSource == AP_NavEKF_Source::SourceZ::RANGEFINDER || !onGround || inFlight) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you see this change is in direct contravention of the comment immediate after it?

@gdavud gdavud force-pushed the EKF3-onGround-issue branch from 3807180 to 2afb4f4 Compare May 5, 2026 08:06
@gdavud gdavud closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants