diff --git a/EKF/ekf.h b/EKF/ekf.h index 18d4987a75..3c14a96343 100644 --- a/EKF/ekf.h +++ b/EKF/ekf.h @@ -49,7 +49,7 @@ class Ekf : public EstimatorInterface public: Ekf() = default; - ~Ekf() = default; + virtual ~Ekf() = default; // initialise variables to sane values (also interface class) bool init(uint64_t timestamp); @@ -122,8 +122,20 @@ public: // get the true airspeed in m/s void get_true_airspeed(float *tas); + // get the full covariance matrix + matrix::SquareMatrix covariances() const { return matrix::SquareMatrix(P); } + // get the diagonal elements of the covariance matrix - void get_covariances(float *covariances); + matrix::Vector covariances_diagonal() const { return covariances().diag(); } + + // get the orientation (quaterion) covariances + matrix::SquareMatrix orientation_covariances() const { return covariances().slice<4, 4>(0, 0); } + + // get the linear velocity covariances + matrix::SquareMatrix velocity_covariances() const { return covariances().slice<3, 3>(4, 4); } + + // get the position covariances + matrix::SquareMatrix position_covariances() const { return covariances().slice<3, 3>(7, 7); } // ask estimator for sensor data collection decision and do any preprocessing if required, returns true if not defined bool collect_gps(const gps_message &gps); diff --git a/EKF/ekf_helper.cpp b/EKF/ekf_helper.cpp index c6e2e35bfc..513104448c 100644 --- a/EKF/ekf_helper.cpp +++ b/EKF/ekf_helper.cpp @@ -982,14 +982,6 @@ void Ekf::get_gyro_bias(float bias[3]) memcpy(bias, temp, 3 * sizeof(float)); } -// get the diagonal elements of the covariance matrix -void Ekf::get_covariances(float *covariances) -{ - for (unsigned i = 0; i < _k_num_states; i++) { - covariances[i] = P[i][i]; - } -} - // get the position and height of the ekf origin in WGS-84 coordinates and time the origin was set // return true if the origin is valid bool Ekf::get_ekf_origin(uint64_t *origin_time, map_projection_reference_s *origin_pos, float *origin_alt) diff --git a/EKF/estimator_interface.h b/EKF/estimator_interface.h index a253504cdc..6cc8e76662 100644 --- a/EKF/estimator_interface.h +++ b/EKF/estimator_interface.h @@ -104,8 +104,6 @@ public: virtual void get_true_airspeed(float *tas) = 0; - virtual void get_covariances(float *covariances) = 0; - // gets the variances for the NED velocity states virtual void get_vel_var(Vector3f &vel_var) = 0;