From 6bd1145006131570acff56b880516827a41909dd Mon Sep 17 00:00:00 2001 From: bresch Date: Tue, 5 Dec 2023 11:47:43 +0100 Subject: [PATCH] ekf2: scope RngCtrl enum --- src/modules/ekf2/EKF/common.h | 4 ++-- src/modules/ekf2/EKF/estimator_interface.cpp | 2 +- src/modules/ekf2/EKF/range_height_control.cpp | 8 ++++---- src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/ekf2/EKF/common.h b/src/modules/ekf2/EKF/common.h index d6bb2ad52b..0f23bd66fe 100644 --- a/src/modules/ekf2/EKF/common.h +++ b/src/modules/ekf2/EKF/common.h @@ -141,7 +141,7 @@ enum class GnssCtrl : uint8_t { YAW = (1<<3) }; -enum RngCtrl : uint8_t { +enum class RngCtrl : uint8_t { DISABLED = 0, CONDITIONAL = 1, ENABLED = 2 @@ -418,7 +418,7 @@ struct parameters { #if defined(CONFIG_EKF2_RANGE_FINDER) // range finder fusion - int32_t rng_ctrl{RngCtrl::CONDITIONAL}; + int32_t rng_ctrl{static_cast(RngCtrl::CONDITIONAL)}; float range_delay_ms{5.0f}; ///< range finder measurement delay relative to the IMU (mSec) float range_noise{0.1f}; ///< observation noise for range finder measurements (m) diff --git a/src/modules/ekf2/EKF/estimator_interface.cpp b/src/modules/ekf2/EKF/estimator_interface.cpp index 19c555202a..f7d78de836 100644 --- a/src/modules/ekf2/EKF/estimator_interface.cpp +++ b/src/modules/ekf2/EKF/estimator_interface.cpp @@ -586,7 +586,7 @@ bool EstimatorInterface::initialise_interface(uint64_t timestamp) #if defined(CONFIG_EKF2_RANGE_FINDER) // using range finder - if ((_params.rng_ctrl != RngCtrl::DISABLED)) { + if ((_params.rng_ctrl != static_cast(RngCtrl::DISABLED))) { max_time_delay_ms = math::max(_params.range_delay_ms, max_time_delay_ms); } #endif // CONFIG_EKF2_RANGE_FINDER diff --git a/src/modules/ekf2/EKF/range_height_control.cpp b/src/modules/ekf2/EKF/range_height_control.cpp index 177b841393..8fede499e5 100644 --- a/src/modules/ekf2/EKF/range_height_control.cpp +++ b/src/modules/ekf2/EKF/range_height_control.cpp @@ -121,8 +121,8 @@ void Ekf::controlRangeHeightFusion() } // determine if we should use height aiding - const bool do_conditional_range_aid = (_params.rng_ctrl == RngCtrl::CONDITIONAL) && isConditionalRangeAidSuitable(); - const bool continuing_conditions_passing = ((_params.rng_ctrl == RngCtrl::ENABLED) || do_conditional_range_aid) + const bool do_conditional_range_aid = (_params.rng_ctrl == static_cast(RngCtrl::CONDITIONAL)) && isConditionalRangeAidSuitable(); + const bool continuing_conditions_passing = ((_params.rng_ctrl == static_cast(RngCtrl::ENABLED)) || do_conditional_range_aid) && measurement_valid && _range_sensor.isDataHealthy(); @@ -165,13 +165,13 @@ void Ekf::controlRangeHeightFusion() } else { if (starting_conditions_passing) { - if ((_params.height_sensor_ref == HeightSensor::RANGE) && (_params.rng_ctrl == RngCtrl::CONDITIONAL)) { + if ((_params.height_sensor_ref == static_cast(HeightSensor::RANGE)) && (_params.rng_ctrl == static_cast(RngCtrl::CONDITIONAL))) { // Range finder is used while hovering to stabilize the height estimate. Don't reset but use it as height reference. ECL_INFO("starting conditional %s height fusion", HGT_SRC_NAME); _height_sensor_ref = HeightSensor::RANGE; bias_est.setBias(_state.pos(2) + measurement); - } else if ((_params.height_sensor_ref == HeightSensor::RANGE) && (_params.rng_ctrl != RngCtrl::CONDITIONAL)) { + } else if ((_params.height_sensor_ref == static_cast(HeightSensor::RANGE)) && (_params.rng_ctrl != static_cast(RngCtrl::CONDITIONAL))) { // Range finder is the primary height source, the ground is now the datum used // to compute the local vertical position ECL_INFO("starting %s height fusion, resetting height", HGT_SRC_NAME); diff --git a/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp b/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp index 73a6c2b8e1..94a9c1aca4 100644 --- a/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp +++ b/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp @@ -57,12 +57,12 @@ void EkfWrapper::setRangeHeightRef() void EkfWrapper::enableRangeHeightFusion() { - _ekf_params->rng_ctrl = RngCtrl::ENABLED; + _ekf_params->rng_ctrl = static_cast(RngCtrl::ENABLED); } void EkfWrapper::disableRangeHeightFusion() { - _ekf_params->rng_ctrl = RngCtrl::DISABLED; + _ekf_params->rng_ctrl = static_cast(RngCtrl::DISABLED); } bool EkfWrapper::isIntendingRangeHeightFusion() const