mirror of https://github.com/ArduPilot/ardupilot
AP_InertialSensor: Move accel/gyro_consistent to AP_IntertialSensor
Move the accel_consistent and gyro_consistent methods from AP_Arming to AP_IntertialSensor
This commit is contained in:
parent
2a55e6a030
commit
fdf56c2ec4
|
@ -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<gyro_count; i++) {
|
||||
if (!use_gyro(i)) {
|
||||
continue;
|
||||
}
|
||||
// get next gyro vector
|
||||
const Vector3f &gyro_vec = get_gyro(i);
|
||||
const Vector3f vec_diff = gyro_vec - prime_gyro_vec;
|
||||
// allow for up to threshold degrees/s difference
|
||||
if (vec_diff.length() > 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<accel_count; i++) {
|
||||
if (!use_accel(i)) {
|
||||
continue;
|
||||
}
|
||||
// get next accel vector
|
||||
const Vector3f &accel_vec = get_accel(i);
|
||||
Vector3f vec_diff = accel_vec - prime_accel_vec;
|
||||
// allow for user-defined difference, threshold m/s/s. Has to pass in last consistent_time_sec seconds
|
||||
float threshold = accel_error_threshold;
|
||||
if (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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue