diff --git a/libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp b/libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp index e6e4d5b6ab..0be1605d2f 100644 --- a/libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp +++ b/libraries/AP_NavEKF3/AP_NavEKF3_Measurements.cpp @@ -6,6 +6,7 @@ #include #include #include +#include extern const AP_HAL::HAL& hal; @@ -35,13 +36,17 @@ void NavEKF3_core::readRangeFinder(void) // use data from two range finders if available for (uint8_t sensorIndex = 0; sensorIndex <= 1; sensorIndex++) { - if ((frontend->_rng.get_orientation(sensorIndex) == ROTATION_PITCH_270) && (frontend->_rng.status(sensorIndex) == RangeFinder::RangeFinder_Good)) { + AP_RangeFinder_Backend *sensor = frontend->_rng.get_backend(sensorIndex); + if (sensor == nullptr) { + continue; + } + if ((sensor->orientation() == ROTATION_PITCH_270) && (sensor->status() == RangeFinder::RangeFinder_Good)) { rngMeasIndex[sensorIndex] ++; if (rngMeasIndex[sensorIndex] > 2) { rngMeasIndex[sensorIndex] = 0; } storedRngMeasTime_ms[sensorIndex][rngMeasIndex[sensorIndex]] = imuSampleTime_ms - 25; - storedRngMeas[sensorIndex][rngMeasIndex[sensorIndex]] = frontend->_rng.distance_cm(sensorIndex) * 0.01f; + storedRngMeas[sensorIndex][rngMeasIndex[sensorIndex]] = sensor->distance_cm() * 0.01f; } // check for three fresh samples diff --git a/libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp b/libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp index 15b7ec2c73..ff9cb7d5cf 100644 --- a/libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp +++ b/libraries/AP_NavEKF3/AP_NavEKF3_PosVelFusion.cpp @@ -7,6 +7,7 @@ #include #include #include +#include extern const AP_HAL::HAL& hal; @@ -753,10 +754,13 @@ void NavEKF3_core::selectHeightForFusion() // the corrected reading is the reading that would have been taken if the sensor was // co-located with the IMU if (rangeDataToFuse) { - Vector3f posOffsetBody = frontend->_rng.get_pos_offset(rangeDataDelayed.sensor_idx) - accelPosOffset; - if (!posOffsetBody.is_zero()) { - Vector3f posOffsetEarth = prevTnb.mul_transpose(posOffsetBody); - rangeDataDelayed.rng += posOffsetEarth.z / prevTnb.c.z; + AP_RangeFinder_Backend *sensor = frontend->_rng.get_backend(rangeDataDelayed.sensor_idx); + if (sensor != nullptr) { + Vector3f posOffsetBody = sensor->get_pos_offset() - accelPosOffset; + if (!posOffsetBody.is_zero()) { + Vector3f posOffsetEarth = prevTnb.mul_transpose(posOffsetBody); + rangeDataDelayed.rng += posOffsetEarth.z / prevTnb.c.z; + } } }