From fdf56c2ec4d4cdea7f4b3bdf8d999df598ab7123 Mon Sep 17 00:00:00 2001 From: Hayden Donald Date: Thu, 9 Nov 2023 13:45:13 +1100 Subject: [PATCH] AP_InertialSensor: Move accel/gyro_consistent to AP_IntertialSensor Move the accel_consistent and gyro_consistent methods from AP_Arming to AP_IntertialSensor --- .../AP_InertialSensor/AP_InertialSensor.cpp | 68 +++++++++++++++++++ .../AP_InertialSensor/AP_InertialSensor.h | 2 + 2 files changed, 70 insertions(+) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.cpp b/libraries/AP_InertialSensor/AP_InertialSensor.cpp index 37504d8897..9450d58447 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor.cpp @@ -1421,6 +1421,35 @@ bool AP_InertialSensor::get_gyro_health_all(void) const return (get_gyro_count() > 0); } +// threshold in degrees/s to be consistent, consistent_time_sec duration for which +// gyros need to be consistent to be considered consistent +bool AP_InertialSensor::gyros_consistent(uint8_t threshold) const +{ + + const uint8_t gyro_count = get_gyro_count(); + if (gyro_count <= 1) { + return true; + } + + const Vector3f &prime_gyro_vec = get_gyro(); + for(uint8_t i=0; i radians(threshold)) { + // this sensor disagrees with the primary sensor, so + // gyros are inconsistent: + return false; + } + } + + return true; +} + // gyro_calibration_ok_all - returns true if all gyros were calibrated successfully bool AP_InertialSensor::gyro_calibrated_ok_all() const { @@ -1460,6 +1489,45 @@ bool AP_InertialSensor::get_accel_health_all(void) const return (get_accel_count() > 0); } +// accel_error_threshold in m/s/s to be consistent +bool AP_InertialSensor::accels_consistent(float accel_error_threshold) const +{ + const uint8_t accel_count = get_accel_count(); + if (accel_count <= 1) { + return true; + } + + const Vector3f &prime_accel_vec = get_accel(); + for(uint8_t i=0; i= 2) { + /* + we allow for a higher threshold for IMU3 as it + runs at a different temperature to IMU1/IMU2, + and is not used for accel data in the EKF + */ + threshold *= 3; + } + + // EKF is less sensitive to Z-axis error + vec_diff.z *= 0.5f; + + if (vec_diff.length() > threshold) { + // this sensor disagrees with the primary sensor, so + // accels are inconsistent: + return false; + } + } + return true; +} + #if HAL_GCS_ENABLED && AP_AHRS_ENABLED /* calculate the trim_roll and trim_pitch. This is used for redoing the diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.h b/libraries/AP_InertialSensor/AP_InertialSensor.h index fd085cf7d3..3df340b673 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor.h @@ -137,6 +137,7 @@ public: bool get_gyro_health(uint8_t instance) const { return (instance<_gyro_count) ? _gyro_healthy[instance] : false; } bool get_gyro_health(void) const { return get_gyro_health(_primary_gyro); } bool get_gyro_health_all(void) const; + bool gyros_consistent(uint8_t threshold) const; uint8_t get_gyro_count(void) const { return MIN(INS_MAX_INSTANCES, _gyro_count); } bool gyro_calibrated_ok(uint8_t instance) const { return _gyro_cal_ok[instance]; } bool gyro_calibrated_ok_all() const; @@ -146,6 +147,7 @@ public: bool get_accel_health(uint8_t instance) const { return (instance<_accel_count) ? _accel_healthy[instance] : false; } bool get_accel_health(void) const { return get_accel_health(_primary_accel); } bool get_accel_health_all(void) const; + bool accels_consistent(float accel_error_threshold) const; uint8_t get_accel_count(void) const { return MIN(INS_MAX_INSTANCES, _accel_count); } bool accel_calibrated_ok_all() const; bool use_accel(uint8_t instance) const;