diff --git a/EKF/ekf.h b/EKF/ekf.h index 65b01acc3c..967d951ce7 100644 --- a/EKF/ekf.h +++ b/EKF/ekf.h @@ -50,6 +50,7 @@ public: static constexpr uint8_t _k_num_states{24}; ///< number of EKF states typedef matrix::Vector Vector24f; typedef matrix::SquareMatrix SquareMatrix24f; + typedef matrix::SquareMatrix Matrix2f; Ekf() = default; virtual ~Ekf() = default; @@ -475,7 +476,7 @@ private: uint64_t _flt_mag_align_start_time{0}; ///< time that inflight magnetic field alignment started (uSec) uint64_t _time_last_mov_3d_mag_suitable{0}; ///< last system time that sufficient movement to use 3-axis magnetometer fusion was detected (uSec) float _saved_mag_bf_variance[4] {}; ///< magnetic field state variances that have been saved for use at the next initialisation (Gauss**2) - float _saved_mag_ef_covmat[2][2] {}; ///< NE magnetic field state covariance sub-matrix saved for use at the next initialisation (Gauss**2) + Matrix2f _saved_mag_ef_covmat; ///< NE magnetic field state covariance sub-matrix saved for use at the next initialisation (Gauss**2) bool _velpos_reset_request{false}; ///< true when a large yaw error has been fixed and a velocity and position state reset is required gps_check_fail_status_u _gps_check_fail_status{}; diff --git a/EKF/ekf_helper.cpp b/EKF/ekf_helper.cpp index 139f6acf4a..8d65a84fce 100644 --- a/EKF/ekf_helper.cpp +++ b/EKF/ekf_helper.cpp @@ -1517,11 +1517,7 @@ void Ekf::saveMagCovData() } // save the NE axis covariance sub-matrix - for (uint8_t row = 0; row <= 1; row ++) { - for (uint8_t col = 0; col <= 1; col ++) { - _saved_mag_ef_covmat[row][col] = P(row + 16,col + 16); - } - } + _saved_mag_ef_covmat = P.slice<2, 2>(16, 16); } void Ekf::loadMagCovData() @@ -1531,11 +1527,7 @@ void Ekf::loadMagCovData() P(index + 18,index + 18) = _saved_mag_bf_variance[index]; } // re-instate the NE axis covariance sub-matrix - for (uint8_t row = 0; row <= 1; row ++) { - for (uint8_t col = 0; col <= 1; col ++) { - P(row + 16,col + 16) = _saved_mag_ef_covmat[row][col]; - } - } + P.slice<2, 2>(16, 16) = _saved_mag_ef_covmat; } void Ekf::stopGpsFusion()