From 1e83ef3c44ac0e88c3339ad25fba379a98948e99 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 8 Aug 2017 16:06:48 +1000 Subject: [PATCH] AP_NavEKF2: use rangefinder backend accessors --- libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp | 9 +++++++-- libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp index fcc4fa27fc..95786a58d1 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -39,13 +40,17 @@ void NavEKF2_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_NavEKF2/AP_NavEKF2_PosVelFusion.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp index 92e6528689..379739948a 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp @@ -6,6 +6,7 @@ #include "AP_NavEKF2_core.h" #include #include +#include #include @@ -744,10 +745,13 @@ void NavEKF2_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; + } } }