From 9b6e7cb8008c14d435c9dd46b457f6de1ed05cee Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Thu, 2 Apr 2026 15:30:24 -0800 Subject: [PATCH] fix(ekf2): allow optical flow to start when range finder is height reference (#26960) When EKF2_HGT_REF=2 (range sensor) with no GPS, optical flow could never start. The starting condition required isTerrainEstimateValid() or isHorizontalAidingActive(), but terrain is never "estimated" when range is the height reference (ground is the datum, terrain state is fixed at 0), and there's no horizontal aiding without GPS. HAGL is directly known from the range measurement in this case, so optical flow has everything it needs to fuse. Add the range height reference check to the optical flow starting conditions. Fixes: https://github.com/PX4/PX4-Autopilot/issues/25248 --- .../ekf2/EKF/aid_sources/optical_flow/optical_flow_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ekf2/EKF/aid_sources/optical_flow/optical_flow_control.cpp b/src/modules/ekf2/EKF/aid_sources/optical_flow/optical_flow_control.cpp index bfbc50c4d8..2fd346f053 100644 --- a/src/modules/ekf2/EKF/aid_sources/optical_flow/optical_flow_control.cpp +++ b/src/modules/ekf2/EKF/aid_sources/optical_flow/optical_flow_control.cpp @@ -157,7 +157,7 @@ void Ekf::controlOpticalFlowFusion(const imuSample &imu_delayed) && is_magnitude_good && is_tilt_good && (_flow_counter > 10) - && (isTerrainEstimateValid() || isHorizontalAidingActive()) + && (isTerrainEstimateValid() || isHorizontalAidingActive() || (_height_sensor_ref == HeightSensor::RANGE)) && isTimedOut(_aid_src_optical_flow.time_last_fuse, (uint64_t)2e6); // Prevent rapid switching // If the height is relative to the ground, terrain height cannot be observed.