Repository navigation
AP_NavEKF3: keep baro ground effect out of a height source switch - #34432
Conversation
With EK3_RNG_USE_HGT, Copter uses a range finder that reads on the ground for height while taking off, so the baro offset filter runs while the motors spool up and learns the prop-wash baro error as offset. ALT_HOLD's takeoff ends as the vehicle leaves the ground, the source goes back to baro there, and the offset carries the error into the flight: in SITL with SIM_BARO_GEFF_M 3 the EKF height read 2.5 m high from then until landing. While takeoff or touchdown is expected, do not update the offset, and do not reset the height to the baro on switching to it. Either alone is not enough: with only the offset held, the reset drops the height by the whole error at liftoff (3.0 m); with only the reset skipped, the offset still carries it (2.5 m). With both, -0.17 m worst in the takeoff and 0.03 m mean above 5 m. Baro drift is not learned while the flags are set, which on Copter includes the whole time it sits armed on the ground. Learning only the upward part of the error was tried: in SITL it did no better, and baro noise ratchets it upwards (0.07 m after a 10 s armed wait with SIM_BARO_RND 0.2). Fixed wing sets the flags for a launch rather than for rotor wash, so it is left as it was.
Fails without the fix (EKF height 2.5 m high above 5 m), with only the baro offset held (3.0 m drop at liftoff) and with only the reset skipped (2.5 m high). Takeoff only; the touchdown half of the fix is not covered.
|
Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting. Full report: https://uav.tridgell.net/DevCallReviews/2026_09_23/devcall_pr_reviews.html#pr34432 Reviewed at head I reproduced your A/B table in SITL rather than taking it on trust — built at this head, then rebuilt with each guard individually disabled (patching only the
So the test is genuinely RED on master, RED for each half of the fix alone, and GREEN only with both — the "either alone is not enough" claim holds. 1.
|
Summary
With EK3_RNG_USE_HGT set and a baro that sees ground effect, a copter's EKF height reads about 2.5 m high for the whole flight. The baro offset learns the ground effect error while the range finder is the height source during the takeoff, and carries it through the switch back to baro. This stops the offset learning, and skips the height reset to the baro, while takeoff or touchdown is expected.
Classification & Testing (check all that apply and add your own)
New autotest BaroGroundEffectRangefinderSwitch: ALT_HOLD takeoff with SIM_BARO_GEFF_M 3, EK3_RNG_USE_HGT 50 and a range finder that reads on the ground, EKF height checked against the SITL truth up to the switch to LAND.
Also passing: Copter TakeoffGroundEffectAlt, TouchdownGroundEffectAlt, RangeFinder, SurfaceTracking, FlyRangeFinderSITL, RangeFinderPowerDown, EK3_RNG_USE_HGT and Replay; QuadPlane Mission, PrecisionLanding, LoiterAltQLand, MAV_CMD_NAV_TAKEOFF, VTOLLandGoAround and TakeoffCheck.
Description
Copter trusts the range finder for height only while taking off or landing (
set_terrain_hgt_stable()). ALT_HOLD's takeoff ends as the vehicle leaves the ground, so the height source goes from range finder back to baro right at liftoff, still in ground effect. Two things then carry the baro error into the flight:calcFiltBaroOffset()has been learning baro minus range height through the spool-up, and the source switch resets the height to that baro. Holding only the offset leaves the reset to drop the height by the whole error at liftoff; skipping only the reset leaves the offset to carry it.Both now key on takeoff or touchdown expected, the flags the height fusion dead zone already uses. The baro is still fused at its ground effect weighting, and the height converges on it once the flags clear.
Baro drift is not learned while the flags are set. I tried letting the offset rise but not fall, since ground effect only reads low, in two forms. Neither did better in SITL: one lets baro noise ratchet the offset upwards (0.07 m after a 10 s armed wait with SIM_BARO_RND 0.2), and the other needs its floor reset everywhere the offset is.
Fixed wing sets the same flags for a launch rather than for rotor wash, so fly-forward vehicles are left as they were. QuadPlane in VTOL gets the change.
Found while testing #32232, whose on-ground range substitution sends a sensor that reads out of range low on the ground down this path too. On master it takes a range finder that reads on the ground. Only the takeoff is tested; touchdown goes through the same two lines.