diff --git a/src/modules/ekf2/EKF/baro_height_control.cpp b/src/modules/ekf2/EKF/baro_height_control.cpp index f3c5b0df643c..def9a885f348 100644 --- a/src/modules/ekf2/EKF/baro_height_control.cpp +++ b/src/modules/ekf2/EKF/baro_height_control.cpp @@ -155,7 +155,7 @@ void Ekf::controlBaroHeightFusion() } else { if (starting_conditions_passing) { - if (_params.height_sensor_ref == HeightSensor::BARO) { + if (_params.height_sensor_ref == static_cast(HeightSensor::BARO)) { ECL_INFO("starting %s height fusion, resetting height", HGT_SRC_NAME); _height_sensor_ref = HeightSensor::BARO; diff --git a/src/modules/ekf2/EKF/common.h b/src/modules/ekf2/EKF/common.h index 0f23bd66fe3e..82e74236a31b 100644 --- a/src/modules/ekf2/EKF/common.h +++ b/src/modules/ekf2/EKF/common.h @@ -114,7 +114,7 @@ enum TerrainFusionMask : uint8_t { }; #endif // CONFIG_EKF2_TERRAIN -enum HeightSensor : uint8_t { +enum class HeightSensor : uint8_t { BARO = 0, GNSS = 1, RANGE = 2, @@ -277,7 +277,7 @@ struct parameters { int32_t imu_ctrl{static_cast(ImuCtrl::GyroBias) | static_cast(ImuCtrl::AccelBias)}; // measurement source control - int32_t height_sensor_ref{HeightSensor::BARO}; + int32_t height_sensor_ref{static_cast(HeightSensor::BARO)}; int32_t position_sensor_ref{static_cast(PositionSensor::GNSS)}; int32_t sensor_interval_max_ms{10}; ///< maximum time of arrival difference between non IMU sensor updates. Sets the size of the observation buffers. (mSec) diff --git a/src/modules/ekf2/EKF/ekf.h b/src/modules/ekf2/EKF/ekf.h index 26244d942eb2..b5af4f523b62 100644 --- a/src/modules/ekf2/EKF/ekf.h +++ b/src/modules/ekf2/EKF/ekf.h @@ -407,7 +407,7 @@ class Ekf final : public EstimatorInterface float getYawVar() const; - uint8_t getHeightSensorRef() const { return _height_sensor_ref; } + HeightSensor getHeightSensorRef() const { return _height_sensor_ref; } #if defined(CONFIG_EKF2_AIRSPEED) const auto &aid_src_airspeed() const { return _aid_src_airspeed; } @@ -1139,7 +1139,7 @@ class Ekf final : public EstimatorInterface // yaw_variance : yaw error variance (rad^2) void resetQuatStateYaw(float yaw, float yaw_variance); - uint8_t _height_sensor_ref{HeightSensor::UNKNOWN}; + HeightSensor _height_sensor_ref{HeightSensor::UNKNOWN}; uint8_t _position_sensor_ref{static_cast(PositionSensor::GNSS)}; #if defined(CONFIG_EKF2_EXTERNAL_VISION) diff --git a/src/modules/ekf2/EKF/ev_height_control.cpp b/src/modules/ekf2/EKF/ev_height_control.cpp index 0a4bc00c847a..c0980a71b3c4 100644 --- a/src/modules/ekf2/EKF/ev_height_control.cpp +++ b/src/modules/ekf2/EKF/ev_height_control.cpp @@ -191,7 +191,7 @@ void Ekf::controlEvHeightFusion(const extVisionSample &ev_sample, const bool com } else { if (starting_conditions_passing) { // activate fusion, only reset if necessary - if (_params.height_sensor_ref == HeightSensor::EV) { + if (_params.height_sensor_ref == static_cast(HeightSensor::EV)) { ECL_INFO("starting %s fusion, resetting state", AID_SRC_NAME); _information_events.flags.reset_hgt_to_ev = true; resetVerticalPositionTo(measurement, measurement_var); diff --git a/src/modules/ekf2/EKF/gnss_height_control.cpp b/src/modules/ekf2/EKF/gnss_height_control.cpp index 600ba088761b..0ea8e932c3e3 100644 --- a/src/modules/ekf2/EKF/gnss_height_control.cpp +++ b/src/modules/ekf2/EKF/gnss_height_control.cpp @@ -136,7 +136,7 @@ void Ekf::controlGnssHeightFusion(const gpsSample &gps_sample) } else { if (starting_conditions_passing) { - if (_params.height_sensor_ref == HeightSensor::GNSS) { + if (_params.height_sensor_ref == static_cast(HeightSensor::GNSS)) { ECL_INFO("starting %s height fusion, resetting height", HGT_SRC_NAME); _height_sensor_ref = HeightSensor::GNSS; diff --git a/src/modules/ekf2/EKF/height_bias_estimator.hpp b/src/modules/ekf2/EKF/height_bias_estimator.hpp index 1d1b9629f51f..5cb03cbfdd13 100644 --- a/src/modules/ekf2/EKF/height_bias_estimator.hpp +++ b/src/modules/ekf2/EKF/height_bias_estimator.hpp @@ -39,11 +39,12 @@ #define EKF_HEIGHT_BIAS_ESTIMATOR_HPP #include "bias_estimator.hpp" +#include "common.h" class HeightBiasEstimator: public BiasEstimator { public: - HeightBiasEstimator(uint8_t sensor, const uint8_t &sensor_ref): + HeightBiasEstimator(HeightSensor sensor, const HeightSensor &sensor_ref): BiasEstimator(0.f, 0.f), _sensor(sensor), _sensor_ref(sensor_ref) @@ -68,8 +69,8 @@ class HeightBiasEstimator: public BiasEstimator } private: - const uint8_t _sensor; - const uint8_t &_sensor_ref; + const HeightSensor _sensor; + const HeightSensor &_sensor_ref; bool _is_sensor_fusion_active{false}; // TODO: replace by const ref and remove setter when migrating _control_status.flags from union to bool }; diff --git a/src/modules/ekf2/EKF/height_control.cpp b/src/modules/ekf2/EKF/height_control.cpp index 0d954663d0a9..9d07c9bc580d 100644 --- a/src/modules/ekf2/EKF/height_control.cpp +++ b/src/modules/ekf2/EKF/height_control.cpp @@ -68,7 +68,7 @@ void Ekf::checkHeightSensorRefFallback() HeightSensor fallback_list[4]; - switch (_params.height_sensor_ref) { + switch (static_cast(_params.height_sensor_ref)) { default: /* FALLTHROUGH */ diff --git a/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp b/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp index 94a9c1aca42f..482f7671eaed 100644 --- a/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp +++ b/src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp @@ -12,7 +12,7 @@ EkfWrapper::~EkfWrapper() void EkfWrapper::setBaroHeightRef() { - _ekf_params->height_sensor_ref = HeightSensor::BARO; + _ekf_params->height_sensor_ref = static_cast(HeightSensor::BARO); } void EkfWrapper::enableBaroHeightFusion() @@ -32,7 +32,7 @@ bool EkfWrapper::isIntendingBaroHeightFusion() const void EkfWrapper::setGpsHeightRef() { - _ekf_params->height_sensor_ref = HeightSensor::GNSS; + _ekf_params->height_sensor_ref = static_cast(HeightSensor::GNSS); } void EkfWrapper::enableGpsHeightFusion() @@ -52,7 +52,7 @@ bool EkfWrapper::isIntendingGpsHeightFusion() const void EkfWrapper::setRangeHeightRef() { - _ekf_params->height_sensor_ref = HeightSensor::RANGE; + _ekf_params->height_sensor_ref = static_cast(HeightSensor::RANGE); } void EkfWrapper::enableRangeHeightFusion() @@ -72,7 +72,7 @@ bool EkfWrapper::isIntendingRangeHeightFusion() const void EkfWrapper::setExternalVisionHeightRef() { - _ekf_params->height_sensor_ref = HeightSensor::EV; + _ekf_params->height_sensor_ref = static_cast(HeightSensor::EV); } void EkfWrapper::enableExternalVisionHeightFusion()