Skip to content

Commit

Permalink
ekf2: scope HeightSensor enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Dec 5, 2023
1 parent 1070ec7 commit ddd0850
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/modules/ekf2/EKF/baro_height_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(HeightSensor::BARO)) {
ECL_INFO("starting %s height fusion, resetting height", HGT_SRC_NAME);
_height_sensor_ref = HeightSensor::BARO;

Expand Down
4 changes: 2 additions & 2 deletions src/modules/ekf2/EKF/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -277,7 +277,7 @@ struct parameters {
int32_t imu_ctrl{static_cast<int32_t>(ImuCtrl::GyroBias) | static_cast<int32_t>(ImuCtrl::AccelBias)};

// measurement source control
int32_t height_sensor_ref{HeightSensor::BARO};
int32_t height_sensor_ref{static_cast<int32_t>(HeightSensor::BARO)};
int32_t position_sensor_ref{static_cast<int32_t>(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)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ekf2/EKF/ekf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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<uint8_t>(PositionSensor::GNSS)};

#if defined(CONFIG_EKF2_EXTERNAL_VISION)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ekf2/EKF/ev_height_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(HeightSensor::EV)) {
ECL_INFO("starting %s fusion, resetting state", AID_SRC_NAME);
_information_events.flags.reset_hgt_to_ev = true;
resetVerticalPositionTo(measurement, measurement_var);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ekf2/EKF/gnss_height_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>(HeightSensor::GNSS)) {
ECL_INFO("starting %s height fusion, resetting height", HGT_SRC_NAME);
_height_sensor_ref = HeightSensor::GNSS;

Expand Down
7 changes: 4 additions & 3 deletions src/modules/ekf2/EKF/height_bias_estimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ekf2/EKF/height_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Ekf::checkHeightSensorRefFallback()

HeightSensor fallback_list[4];

switch (_params.height_sensor_ref) {
switch (static_cast<HeightSensor>(_params.height_sensor_ref)) {
default:

/* FALLTHROUGH */
Expand Down
8 changes: 4 additions & 4 deletions src/modules/ekf2/test/sensor_simulator/ekf_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EkfWrapper::~EkfWrapper()

void EkfWrapper::setBaroHeightRef()
{
_ekf_params->height_sensor_ref = HeightSensor::BARO;
_ekf_params->height_sensor_ref = static_cast<int32_t>(HeightSensor::BARO);
}

void EkfWrapper::enableBaroHeightFusion()
Expand All @@ -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<int32_t>(HeightSensor::GNSS);
}

void EkfWrapper::enableGpsHeightFusion()
Expand All @@ -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<int32_t>(HeightSensor::RANGE);
}

void EkfWrapper::enableRangeHeightFusion()
Expand All @@ -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<int32_t>(HeightSensor::EV);
}

void EkfWrapper::enableExternalVisionHeightFusion()
Expand Down

0 comments on commit ddd0850

Please sign in to comment.