From 5ab89324b232b21c380434b5956e14c46e8f9c58 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 6 Mar 2018 07:35:34 +1100 Subject: [PATCH] AP_NavEKF2: use baro singleton --- libraries/AP_NavEKF2/AP_NavEKF2.cpp | 5 ++--- libraries/AP_NavEKF2/AP_NavEKF2.h | 3 +-- libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp | 7 ++++--- libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2.cpp b/libraries/AP_NavEKF2/AP_NavEKF2.cpp index 04b2e5097e..96962aca44 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2.cpp @@ -555,9 +555,8 @@ const AP_Param::GroupInfo NavEKF2::var_info[] = { AP_GROUPEND }; -NavEKF2::NavEKF2(const AP_AHRS *ahrs, AP_Baro &baro, const RangeFinder &rng) : +NavEKF2::NavEKF2(const AP_AHRS *ahrs, const RangeFinder &rng) : _ahrs(ahrs), - _baro(baro), _rng(rng) { AP_Param::setup_object_defaults(this, var_info); @@ -580,7 +579,7 @@ void NavEKF2::check_log_write(void) logging.log_gps = false; } if (logging.log_baro) { - DataFlash_Class::instance()->Log_Write_Baro(_baro, imuSampleTime_us); + DataFlash_Class::instance()->Log_Write_Baro(imuSampleTime_us); logging.log_baro = false; } if (logging.log_imu) { diff --git a/libraries/AP_NavEKF2/AP_NavEKF2.h b/libraries/AP_NavEKF2/AP_NavEKF2.h index 670e4eede4..307e66bb11 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2.h +++ b/libraries/AP_NavEKF2/AP_NavEKF2.h @@ -38,7 +38,7 @@ class NavEKF2 { friend class NavEKF2_core; public: - NavEKF2(const AP_AHRS *ahrs, AP_Baro &baro, const RangeFinder &rng); + NavEKF2(const AP_AHRS *ahrs, const RangeFinder &rng); /* Do not allow copies */ NavEKF2(const NavEKF2 &other) = delete; @@ -328,7 +328,6 @@ private: uint8_t primary; // current primary core NavEKF2_core *core = nullptr; const AP_AHRS *_ahrs; - AP_Baro &_baro; const RangeFinder &_rng; uint32_t _frameTimeUsec; // time per IMU frame diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp index 881445c3be..540a1ba536 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_Measurements.cpp @@ -556,10 +556,11 @@ void NavEKF2_core::readBaroData() { // check to see if baro measurement has changed so we know if a new measurement has arrived // do not accept data at a faster rate than 14Hz to avoid overflowing the FIFO buffer - if (frontend->_baro.get_last_update() - lastBaroReceived_ms > 70) { + const AP_Baro &baro = AP::baro(); + if (baro.get_last_update() - lastBaroReceived_ms > 70) { frontend->logging.log_baro = true; - baroDataNew.hgt = frontend->_baro.get_altitude(); + baroDataNew.hgt = baro.get_altitude(); // If we are in takeoff mode, the height measurement is limited to be no less than the measurement at start of takeoff // This prevents negative baro disturbances due to copter downwash corrupting the EKF altitude during initial ascent @@ -568,7 +569,7 @@ void NavEKF2_core::readBaroData() } // time stamp used to check for new measurement - lastBaroReceived_ms = frontend->_baro.get_last_update(); + lastBaroReceived_ms = baro.get_last_update(); // estimate of time height measurement was taken, allowing for delays baroDataNew.time_ms = lastBaroReceived_ms - frontend->_hgtDelay_ms; diff --git a/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp index 210a6467d8..715f755469 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2_PosVelFusion.cpp @@ -204,7 +204,7 @@ bool NavEKF2_core::resetHeightDatum(void) // record the old height estimate float oldHgt = -stateStruct.position.z; // reset the barometer so that it reads zero at the current height - frontend->_baro.update_calibration(); + AP::baro().update_calibration(); // reset the height state stateStruct.position.z = 0.0f; // adjust the height of the EKF origin so that the origin plus baro height before and after the reset is the same