EKF: Rework use of fuseDeclination()

Simplify calling so that it is only called in two ways:
1) Immediately before 3-axis mag fusion if not called since the last earth field covariance reset so that the earth field declination information can be formed.
2) Immediately after 3-axis mag fusion otherwise.
This commit is contained in:
Paul Riseborough
2019-01-31 09:53:57 -05:00
committed by Daniel Agar
parent d52f53635b
commit bd1647a7fb
4 changed files with 28 additions and 24 deletions
+2 -3
View File
@@ -847,6 +847,7 @@ void Ekf::fixCovarianceErrors()
if (!_control_status.flags.mag_3D) {
zeroRows(P, 16, 21);
zeroCols(P, 16, 21);
_mag_decl_cov_reset = false;
} else {
// constrain variances
@@ -887,15 +888,13 @@ void Ekf::resetMagCovariance()
// set the magnetic field covariance terms to zero
zeroRows(P, 16, 21);
zeroCols(P, 16, 21);
_mag_decl_cov_reset = false;
// set the field state variance to the observation variance
for (uint8_t rc_index = 16; rc_index <= 21; rc_index ++) {
P[rc_index][rc_index] = sq(_params.mag_noise);
}
// Fuse the declination angle to prevent rapid rotation of earth field vector estimates
fuseDeclination(0.02f);
// save covariance data for re-use when auto-switching between heading and 3-axis fusion
save_mag_cov_data();
}