mars_lib  0.1.0.3dc76ee85e09
Modular and Robust Sensor-Fusion
ekf.h
Go to the documentation of this file.
1 // Copyright (C) 2022 Christian Brommer, Control of Networked Systems, University of Klagenfurt, Austria.
2 //
3 // All rights reserved.
4 //
5 // This software is licensed under the terms of the BSD-2-Clause-License with
6 // no commercial use allowed, the full terms of which are made available
7 // in the LICENSE file. No license in patents is granted.
8 //
9 // You can contact the author at <christian.brommer@ieee.org>
10 
11 #ifndef EKF_HPP
12 #define EKF_HPP
13 
14 #include <Eigen/Dense>
15 #include <boost/math/distributions/chi_squared.hpp>
16 #include <iostream>
17 
18 namespace mars
19 {
20 class Chi2
21 {
22 public:
26  Chi2();
27 
33  Chi2(const int& dof, const double& chi_value);
34 
39  void set_dof(const int& value);
40 
45  void set_chi_value(const double& value);
46 
52  void get_result(Eigen::MatrixXd* const last_res, double* const last_X2) const;
53 
57  void CalculateUcv();
58 
63  void ActivateTest(const bool& value);
64 
71  bool CalculateChi2(const Eigen::MatrixXd& res, const Eigen::MatrixXd& S);
72 
77  void PrintReport(const std::string& name);
78 
79  boost::math::chi_squared dist_;
80  int dof_{ 3 };
81  double chi_value_{ 0.05 };
82  double ucv_;
83  bool do_test_{ true };
84  bool passed_{ false };
85 
86 private:
87  Eigen::MatrixXd last_res_;
88  double last_X2_;
89 };
90 
91 class Ekf
92 {
93 public:
94  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
95 
103  Ekf(const Eigen::Ref<const Eigen::MatrixXd>& H, const Eigen::Ref<const Eigen::MatrixXd>& R,
104  const Eigen::Ref<const Eigen::MatrixXd>& res, const Eigen::Ref<const Eigen::MatrixXd>& P)
105  {
106  this->H_ = H;
107  this->R_ = R;
108  this->res_ = res;
109  this->P_ = P;
110  }
111 
112  Eigen::MatrixXd H_;
113  Eigen::MatrixXd R_;
114  Eigen::MatrixXd res_;
115  Eigen::MatrixXd P_;
116  Eigen::MatrixXd S_;
117  Eigen::MatrixXd K_;
118 
123  Eigen::MatrixXd CalculateCorrection();
129  Eigen::MatrixXd CalculateCorrection(Chi2* chi2);
134  Eigen::MatrixXd CalculateCovUpdate();
135 
136 private:
141  Eigen::MatrixXd CalculateStateCorrection();
142 };
143 } // namespace mars
144 
145 #endif // EKF_HPP
Definition: ekf.h:21
bool passed_
Determine if the test is performed or not.
Definition: ekf.h:84
bool CalculateChi2(const Eigen::MatrixXd &res, const Eigen::MatrixXd &S)
CalculateChi2 Calculate the X2 value and compare it to the upper critical value (UCV)
void set_chi_value(const double &value)
set_chi_value Set chi value for the calculation of the upper critical value
int dof_
Chi2 distribution, generated based on the DoF.
Definition: ekf.h:80
Chi2(const int &dof, const double &chi_value)
Chi2 Constructor.
void get_result(Eigen::MatrixXd *const last_res, double *const last_X2) const
get_result Returns the last report values, i.e. last residual and X2 value
bool do_test_
Upper critival value.
Definition: ekf.h:83
double ucv_
Chi value for the confidence intervall (0.05 represents 95% test)
Definition: ekf.h:82
void set_dof(const int &value)
set_dof Set degree of freedom for the X2 distribution
void ActivateTest(const bool &value)
ActivateTest Enable or disable the X2 test.
Chi2()
Chi2 Default constructor.
Eigen::MatrixXd last_res_
Shows if the test passed or not (true=passed)
Definition: ekf.h:87
double chi_value_
Degrees of freedom for the setup.
Definition: ekf.h:81
boost::math::chi_squared dist_
Definition: ekf.h:79
double last_X2_
Last residual, for the report.
Definition: ekf.h:88
void PrintReport(const std::string &name)
PrintReport Print a formated report e.g. if the test did not pass.
void CalculateUcv()
CalculateUcv Perform the calculation of the upper critical value.
Definition: ekf.h:92
Eigen::MatrixXd H_
Definition: ekf.h:112
Eigen::MatrixXd res_
Measurement noise.
Definition: ekf.h:114
Eigen::MatrixXd P_
Residual.
Definition: ekf.h:115
Eigen::MatrixXd CalculateCorrection(Chi2 *chi2)
CalculateCorrection Calculating the state correction with a post Chi2 test.
Eigen::MatrixXd CalculateStateCorrection()
CalculateStateCorrection Calculation of EKF components, correction, innovation etc.
Eigen::MatrixXd CalculateCovUpdate()
CalculateCovUpdate Updating the state covariance after the state update.
Eigen::MatrixXd S_
State covariance.
Definition: ekf.h:116
Eigen::MatrixXd K_
Innovation / variance of the residual.
Definition: ekf.h:117
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Ekf(const Eigen::Ref< const Eigen::MatrixXd > &H, const Eigen::Ref< const Eigen::MatrixXd > &R, const Eigen::Ref< const Eigen::MatrixXd > &res, const Eigen::Ref< const Eigen::MatrixXd > &P)
Ekf Essential EFK update component.
Definition: ekf.h:103
Eigen::MatrixXd CalculateCorrection()
Kalman gain.
Eigen::MatrixXd R_
Jacobian.
Definition: ekf.h:113
Definition: buffer.h:27