AP_NavEKF3: make AP_RANGEFINDER_ENABLED remove more code

This commit is contained in:
Peter Barker 2023-11-08 09:23:40 +11:00 committed by Andrew Tridgell
parent 0f47cd7e8b
commit 13e7d04497
6 changed files with 23 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <AP_DAL/AP_DAL.h>
#include <AP_InternalError/AP_InternalError.h>
#if AP_RANGEFINDER_ENABLED
/********************************************************
* OPT FLOW AND RANGE FINDER *
********************************************************/
@ -105,6 +106,7 @@ void NavEKF3_core::readRangeFinder(void)
}
}
}
#endif // AP_RANGEFINDER_ENABLED
void NavEKF3_core::writeBodyFrameOdom(float quality, const Vector3f &delPos, const Vector3f &delAng, float delTime, uint32_t timeStamp_ms, uint16_t delay_ms, const Vector3f &posOffset)
{

View File

@ -68,12 +68,16 @@ bool NavEKF3_core::getHeightControlLimit(float &height) const
// only ask for limiting if we are doing optical flow navigation
if (frontend->sources.useVelXYSource(AP_NavEKF_Source::SourceXY::OPTFLOW) && (PV_AidingMode == AID_RELATIVE) && flowDataValid) {
// If are doing optical flow nav, ensure the height above ground is within range finder limits after accounting for vehicle tilt and control errors
#if AP_RANGEFINDER_ENABLED
const auto *_rng = dal.rangefinder();
if (_rng == nullptr) {
// we really, really shouldn't be here.
return false;
}
height = MAX(float(_rng->max_distance_cm_orient(ROTATION_PITCH_270)) * 0.007f - 1.0f, 1.0f);
#else
return false;
#endif
// If we are are not using the range finder as the height reference, then compensate for the difference between terrain and EKF origin
if (frontend->sources.getPosZSource() != AP_NavEKF_Source::SourceZ::RANGEFINDER) {
height -= terrainState;

View File

@ -1128,6 +1128,7 @@ void NavEKF3_core::FuseVelPosNED()
// select the height measurement to be fused from the available baro, range finder and GPS sources
void NavEKF3_core::selectHeightForFusion()
{
#if AP_RANGEFINDER_ENABLED
// Read range finder data and check for new data in the buffer
// This data is used by both height and optical flow fusion processing
readRangeFinder();
@ -1147,6 +1148,7 @@ void NavEKF3_core::selectHeightForFusion()
}
}
}
#endif // AP_RANGEFINDER_ENABLED
// read baro height data from the sensor and check for new data in the buffer
readBaroData();
@ -1160,6 +1162,7 @@ void NavEKF3_core::selectHeightForFusion()
if ((frontend->sources.getPosZSource() == AP_NavEKF_Source::SourceZ::NONE)) {
// user has specified no height sensor
activeHgtSource = AP_NavEKF_Source::SourceZ::NONE;
#if AP_RANGEFINDER_ENABLED
} else if ((frontend->sources.getPosZSource() == AP_NavEKF_Source::SourceZ::RANGEFINDER) && _rng && rangeFinderDataIsFresh) {
// user has specified the range finder as a primary height source
activeHgtSource = AP_NavEKF_Source::SourceZ::RANGEFINDER;
@ -1201,6 +1204,7 @@ void NavEKF3_core::selectHeightForFusion()
// reliable terrain and range finder so start using range finder height
activeHgtSource = AP_NavEKF_Source::SourceZ::RANGEFINDER;
}
#endif
} else if (frontend->sources.getPosZSource() == AP_NavEKF_Source::SourceZ::BARO) {
activeHgtSource = AP_NavEKF_Source::SourceZ::BARO;
} else if ((frontend->sources.getPosZSource() == AP_NavEKF_Source::SourceZ::GPS) && ((imuSampleTime_ms - lastTimeGpsReceived_ms) < 500) && validOrigin && gpsAccuracyGood) {

View File

@ -131,10 +131,12 @@ bool NavEKF3_core::setup_core(uint8_t _imu_index, uint8_t _core_index)
if(frontend->sources.gps_yaw_enabled() && !storedYawAng.init(obs_buffer_length)) {
return false;
}
#if AP_RANGEFINDER_ENABLED
// Note: the use of dual range finders potentially doubles the amount of data to be stored
if(dal.rangefinder() && !storedRange.init(MIN(2*obs_buffer_length , imu_buffer_length))) {
return false;
}
#endif
// Note: range beacon data is read one beacon at a time and can arrive at a high rate
#if EK3_FEATURE_BEACON_FUSION
if(dal.beacon() && !rngBcn.storedRange.init(imu_buffer_length+1)) {
@ -338,9 +340,11 @@ void NavEKF3_core::InitialiseVariables()
memset(&filterStatus, 0, sizeof(filterStatus));
activeHgtSource = AP_NavEKF_Source::SourceZ::BARO;
prevHgtSource = activeHgtSource;
#if EK3_FEATURE_RANGEFINDER_MEASUREMENTS
memset(&rngMeasIndex, 0, sizeof(rngMeasIndex));
memset(&storedRngMeasTime_ms, 0, sizeof(storedRngMeasTime_ms));
memset(&storedRngMeas, 0, sizeof(storedRngMeas));
#endif
terrainHgtStable = true;
ekfOriginHgtVar = 0.0f;
ekfGpsRefHgt = 0.0;

View File

@ -110,11 +110,13 @@
#define WIND_VEL_VARIANCE_MIN 0.25f
// maximum number of downward facing rangefinder instances available
#if EK3_FEATURE_RANGEFINDER_MEASUREMENTS
#if RANGEFINDER_MAX_INSTANCES > 1
#define DOWNWARD_RANGEFINDER_MAX_INSTANCES 2
#else
#define DOWNWARD_RANGEFINDER_MAX_INSTANCES 1
#endif
#endif
// number of continuous valid GPS velocity samples required to reset yaw
#define GPS_VEL_YAW_ALIGN_COUNT_THRESHOLD 5
@ -1293,9 +1295,11 @@ private:
ftype rngOnGnd; // Expected range finder reading in metres when vehicle is on ground
uint32_t lastRngMeasTime_ms; // Timestamp of last range measurement
bool terrainHgtStable; // true when the terrain height is stable enough to be used as a height reference
#if EK3_FEATURE_RANGEFINDER_MEASUREMENTS
ftype storedRngMeas[DOWNWARD_RANGEFINDER_MAX_INSTANCES][3]; // Ringbuffer of stored range measurements for dual range sensors
uint32_t storedRngMeasTime_ms[DOWNWARD_RANGEFINDER_MAX_INSTANCES][3]; // Ringbuffers of stored range measurement times for dual range sensors
uint8_t rngMeasIndex[DOWNWARD_RANGEFINDER_MAX_INSTANCES]; // Current range measurement ringbuffer index for dual range sensors
#endif
// body frame odometry fusion
#if EK3_FEATURE_BODY_ODOM

View File

@ -35,3 +35,8 @@
#ifndef EK3_FEATURE_POSITION_RESET
#define EK3_FEATURE_POSITION_RESET EK3_FEATURE_ALL || AP_AHRS_POSITION_RESET_ENABLED
#endif
// rangefinder measurements if available
#ifndef EK3_FEATURE_RANGEFINDER_MEASUREMENTS
#define EK3_FEATURE_RANGEFINDER_MEASUREMENTS AP_RANGEFINDER_ENABLED
#endif