From 63c06ea2afac5fb5e46fd2233ffe1291d2b2cc62 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Oct 2014 10:12:50 +1100 Subject: [PATCH] AP_AHRS: fixed calls to DCM in parent class use_compass() and reset() are common to AP_AHRS_DCM and AP_AHRS_NavEKF. As AP_AHRS_NavEKF is a child of AP_AHRS_DCM, when we call use_compass() from within AP_AHRS_DCM we actually end up calling AP_AHRS_NavEKF::use_compass(). This has the effect of disabling the compass in DCM when EKF is active and EKF has decided not to use the compass. That means that the DCM yaw (and in fact the whole attitude) can get badly off while EKF is enabled, making DCM an ineffective fallback if EKF fails. The fix is to call the specific class versions of use_compass() and reset() --- libraries/AP_AHRS/AP_AHRS_DCM.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/AP_AHRS/AP_AHRS_DCM.cpp b/libraries/AP_AHRS/AP_AHRS_DCM.cpp index 9f79bcd45c..e925aa85a7 100644 --- a/libraries/AP_AHRS/AP_AHRS_DCM.cpp +++ b/libraries/AP_AHRS/AP_AHRS_DCM.cpp @@ -143,7 +143,7 @@ AP_AHRS_DCM::check_matrix(void) { if (_dcm_matrix.is_nan()) { //Serial.printf("ERROR: DCM matrix NAN\n"); - reset(true); + AP_AHRS_DCM::reset(true); return; } // some DCM matrix values can lead to an out of range error in @@ -161,7 +161,7 @@ AP_AHRS_DCM::check_matrix(void) // in real trouble. All we can do is reset //Serial.printf("ERROR: DCM matrix error. _dcm_matrix.c.x=%f\n", // _dcm_matrix.c.x); - reset(true); + AP_AHRS_DCM::reset(true); } } } @@ -242,7 +242,7 @@ AP_AHRS_DCM::normalize(void) // Our solution is blowing up and we will force back // to last euler angles _last_failure_ms = hal.scheduler->millis(); - reset(true); + AP_AHRS_DCM::reset(true); } } @@ -362,7 +362,7 @@ AP_AHRS_DCM::drift_correction_yaw(void) float yaw_error; float yaw_deltat; - if (use_compass()) { + if (AP_AHRS_DCM::use_compass()) { /* we are using compass for yaw */ @@ -684,7 +684,7 @@ AP_AHRS_DCM::drift_correction(float deltat) // reduce the impact of the gps/accelerometers on yaw when we are // flat, but still allow for yaw correction using the // accelerometers at high roll angles as long as we have a GPS - if (use_compass()) { + if (AP_AHRS_DCM::use_compass()) { if (have_gps() && gps_gain == 1.0f) { error[besti].z *= sinf(fabsf(roll)); } else {