From eccfdff7f83bd43c77b19ccc21aa29e09c6a1f03 Mon Sep 17 00:00:00 2001 From: Andrea Bernasconi Date: Thu, 12 Nov 2026 11:16:56 +0100 Subject: [PATCH] feat(sensors): report an outvoted IMU with SENS_IMU_MODE 2 The median outvotes a faulty IMU silently and commander's consistency check stops when armed, so nothing told the pilot that the redundancy was gone and that a second bad IMU could win the vote. Raise a warning event, once per IMU, when one of three or more IMUs is further from the others than a fixed limit. The limit is loose, a few times the preflight ones, since the median already bounds the fault and a late warning costs nothing. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Andrea Bernasconi --- src/modules/sensors/voted_sensors_update.cpp | 37 ++++++++++++++++++++ src/modules/sensors/voted_sensors_update.h | 9 +++++ 2 files changed, 46 insertions(+) diff --git a/src/modules/sensors/voted_sensors_update.cpp b/src/modules/sensors/voted_sensors_update.cpp index 403165a6b57..b14bc719cdd 100644 --- a/src/modules/sensors/voted_sensors_update.cpp +++ b/src/modules/sensors/voted_sensors_update.cpp @@ -402,6 +402,37 @@ bool VotedSensorsUpdate::checkFailover(SensorData &sensor, const char *sensor_na return false; } +void VotedSensorsUpdate::checkOutlier(SensorData &sensor, const uint32_t device_ids[MAX_SENSOR_COUNT], + const float inconsistency[MAX_SENSOR_COUNT], float limit, events::px4::enums::sensor_type_t sensor_type) +{ + int count = 0; + uint8_t worst = 0; + + for (uint8_t i = 0; i < MAX_SENSOR_COUNT; i++) { + if (device_ids[i] != 0) { + count++; + + if (inconsistency[i] > inconsistency[worst]) { + worst = i; + } + } + } + + // two IMUs are equally far from their mean, which names neither + if ((count >= 3) && (inconsistency[worst] > limit) && !(sensor.outlier_reported & (1u << worst))) { + sensor.outlier_reported |= (1u << worst); + + /* EVENT + * @description + * The sensor disagrees with the other IMUs and is outvoted by their median. + * A fault of a second IMU can no longer be outvoted: land and check the system. + */ + events::send( + events::ID("sensor_imu_outlier"), events::Log::Warning, "{1} sensor #{2} outvoted by the other IMUs", sensor_type, + worst); + } +} + void VotedSensorsUpdate::initSensorClass(SensorData &sensor_data, uint8_t sensor_count_max) { bool added = false; @@ -481,6 +512,12 @@ void VotedSensorsUpdate::sensorsPoll(sensor_combined_s &raw) } } + if (_param_sens_imu_mode.get() == 2) { + checkOutlier(_accel, status.accel_device_ids, status.accel_inconsistency_m_s_s, ACCEL_OUTLIER_LIMIT, + events::px4::enums::sensor_type_t::accel); + checkOutlier(_gyro, status.gyro_device_ids, status.gyro_inconsistency_rad_s, GYRO_OUTLIER_LIMIT, + events::px4::enums::sensor_type_t::gyro); + } status.timestamp = hrt_absolute_time(); _sensors_status_imu_pub.publish(status); diff --git a/src/modules/sensors/voted_sensors_update.h b/src/modules/sensors/voted_sensors_update.h index dd3d8b4a89c..9124561badc 100644 --- a/src/modules/sensors/voted_sensors_update.h +++ b/src/modules/sensors/voted_sensors_update.h @@ -109,6 +109,10 @@ private: static constexpr uint8_t DEFAULT_PRIORITY = 50; + // loose on purpose, the median already bounds the fault: several times the preflight limits (COM_ARM_IMU_xxx) + static constexpr float ACCEL_OUTLIER_LIMIT = 2.f; // m/s^2 + static constexpr float GYRO_OUTLIER_LIMIT = 0.5f; // rad/s + struct SensorData { SensorData() = delete; explicit SensorData(ORB_ID meta) : subscription{{meta, 0}, {meta, 1}, {meta, 2}, {meta, 3}} {} @@ -116,6 +120,7 @@ private: uORB::Subscription subscription[MAX_SENSOR_COUNT]; /**< raw sensor data subscription */ DataValidatorGroup voter{1}; unsigned int last_failover_count{0}; + uint8_t outlier_reported{0}; /**< bitmask of the IMUs already reported as the outlier */ int32_t priority[MAX_SENSOR_COUNT] {}; int32_t priority_configured[MAX_SENSOR_COUNT] {}; uint8_t last_best_vote{0}; /**< index of the latest best vote */ @@ -149,6 +154,10 @@ private: */ bool checkFailover(SensorData &sensor, const char *sensor_name, events::px4::enums::sensor_type_t sensor_type); + // SENS_IMU_MODE 2 outvotes a faulty IMU silently: report once the IMU furthest from the others + void checkOutlier(SensorData &sensor, const uint32_t device_ids[MAX_SENSOR_COUNT], + const float inconsistency[MAX_SENSOR_COUNT], float limit, events::px4::enums::sensor_type_t sensor_type); + // VehicleIMU publishes an IMU only while both of its sensors are enabled, so disabling // either one takes the whole IMU out of the vote bool imuEnabled(uint8_t index) const { return (_accel.priority[index] > 0) && (_gyro.priority[index] > 0); }