ekf2: `_position_sensor_ref` plumbing is unused / half-finished
Summary
_position_sensor_ref (src/modules/ekf2/EKF/ekf.h:1052) is declared and passed by reference into _ev_pos_b_est (PositionBiasEstimator), but it is never actually assigned anywhere — it stays at its default PositionSensor::GNSS for the lifetime of the EKF. The only call site that would change it is commented out in ev_pos_control.cpp:221:
//_position_sensor_ref = PositionSensor::EV;Why this matters
PositionBiasEstimator::predict() and fuseBias() both gate on (_sensor_ref != _sensor) && _is_sensor_fusion_active. For _ev_pos_b_est we always have _sensor = EV and _sensor_ref = GNSS, so the != check is a tautology. The "the EV bias should not be predicted/fused when EV is itself the position reference" semantics that the design clearly intended (and that _height_sensor_ref actually implements correctly for the height bias estimators) is not wired up for horizontal position.
In practice this means: when EV is the only horizontal aiding source and there is no GNSS, the EV bias estimator still runs as if GNSS were the reference. The control logic in controlEvPosFusion() papers over this by toggling setFusionActive() / setFusionInactive() based on _control_status.flags.gnss_pos, which mostly works, but it conflates two different concepts:
- "Is GNSS available right now?" (drives
fusionActive) - "What is the position reference frame?" (should drive
_position_sensor_ref)
This conflation is the root cause behind several follow-on items already noted in #26794:
- An explicit "GPS local frame" / "EV local frame"
control_statusflag is missing —gnss_posis being used as a proxy. - Re-acquiring GNSS after running EV-only causes a position jump because there is no separate notion of "we are currently anchored in the EV frame".
startEvPosFusion()always discards a learned bias on the!gnss_pospath because it has no way to remember whether the EV frame was previously aligned.
Suggested direction
Either:
- Wire up
_position_sensor_refsymmetrically to_height_sensor_ref: assign it from the appropriate aid-source control function when EV (or any non-GNSS source) becomes the active position reference, and let the bias estimator's existing guard do the right thing. - Or remove
_position_sensor_refentirely if the design has moved away from this model, and replace it with a realcontrol_statusflag tracking the active position frame.
Either way, the current half-finished state is misleading — the comment in ev_pos_control.cpp:221 reads as if the plumbing works, but it doesn't.
Related
- #26794 (preserve EV position bias on reset when GNSS inactive) — the broader-scope bullets there overlap heavily with this.
- #27094 (height bias guard) and #27304 (horizontal bias guard) — the EV position bias estimator is the only one whose
_sensor_refis actually static, which is why the analogous guard pattern looks slightly redundant for it today.
Source: PX4/PX4-Autopilot