mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
kalman_filter_aloamgarm.h
Go to the documentation of this file.
1 // clang: MatousFormat
7 #ifndef SYSTEMMODELALOAMGARM_H
8 #define SYSTEMMODELALOAMGARM_H
9 
10 #include <Eigen/Dense>
11 
12 #include <boost/circular_buffer.hpp>
13 #include <ros/ros.h>
14 
15 namespace mrs_lib
16 {
17  /* KalmanFilter virtual class //{ */
26  template <int n_states, int n_inputs, int n_measurements>
28  {
29  public:
30  /* states, inputs etc. definitions (typedefs, constants etc) //{ */
31  static const int n = n_states;
32  static const int m = n_inputs;
33  static const int p = n_measurements;
35  typedef Eigen::Matrix<double, n, 1> x_t;
36  typedef Eigen::Matrix<double, m, 1> u_t;
37  typedef Eigen::Matrix<double, p, 1> z_t;
39  typedef Eigen::Matrix<double, n, n> P_t;
40  typedef Eigen::Matrix<double, p, p> R_t;
41  typedef Eigen::Matrix<double, n, n> Q_t;
42  //}
43 
44  /* statecov_t struct //{ */
48  struct statecov_t
49  {
50  x_t x;
51  P_t P;
52  std::shared_ptr<boost::circular_buffer<double>> nis_buffer = nullptr;
53  ros::Time stamp = ros::Time(0);
54  bool measurement_jumped = false;
55 
56  statecov_t& operator=(statecov_t other)
57  {
58  if (this != &other) // not a self-assignment
59  {
60  x = other.x;
61  P = other.P;
62  stamp = other.stamp;
63  if (other.nis_buffer != nullptr){
64  nis_buffer = std::make_shared<boost::circular_buffer<double>>(*other.nis_buffer);
65  }
66  measurement_jumped = other.measurement_jumped;
67  }
68  return *this;
69  }
70 
71  };
72  //}
73 
74  public:
87  virtual statecov_t correct(const statecov_t& sc, const z_t& z, const R_t& R) const = 0;
88 
103  virtual statecov_t predict(const statecov_t& sc, const u_t& u, const Q_t& Q, double dt) const = 0;
104  };
105  //}
106 }
107 
108 #endif // SYSTEMMODELALOAMGARM_H
mrs_lib::KalmanFilterAloamGarm::n
static const int n
Length of the state vector of the system.
Definition: kalman_filter_aloamgarm.h:31
mrs_lib::KalmanFilterAloamGarm::p
static const int p
Length of the measurement vector of the system.
Definition: kalman_filter_aloamgarm.h:33
mrs_lib::KalmanFilterAloamGarm::statecov_t::x
x_t x
State vector.
Definition: kalman_filter_aloamgarm.h:50
mrs_lib::KalmanFilterAloamGarm::predict
virtual statecov_t predict(const statecov_t &sc, const u_t &u, const Q_t &Q, double dt) const =0
Applies the prediction (time) step of the Kalman filter.
mrs_lib::KalmanFilterAloamGarm::R_t
Eigen::Matrix< double, p, p > R_t
Measurement noise covariance matrix type .
Definition: kalman_filter_aloamgarm.h:40
mrs_lib::KalmanFilterAloamGarm::Q_t
Eigen::Matrix< double, n, n > Q_t
Process noise covariance matrix type .
Definition: kalman_filter_aloamgarm.h:41
mrs_lib::KalmanFilterAloamGarm::statecov_t
Helper struct for passing around the state and its covariance in one variable.
Definition: kalman_filter_aloamgarm.h:48
mrs_lib::KalmanFilterAloamGarm
This abstract class defines common interfaces and types for a generic Kalman filter.
Definition: kalman_filter_aloamgarm.h:27
mrs_lib::KalmanFilterAloamGarm::u_t
Eigen::Matrix< double, m, 1 > u_t
Input vector type .
Definition: kalman_filter_aloamgarm.h:36
mrs_lib::KalmanFilterAloamGarm::correct
virtual statecov_t correct(const statecov_t &sc, const z_t &z, const R_t &R) const =0
Applies the correction (update, measurement, data) step of the Kalman filter.
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
mrs_lib::KalmanFilterAloamGarm::z_t
Eigen::Matrix< double, p, 1 > z_t
Measurement vector type .
Definition: kalman_filter_aloamgarm.h:37
mrs_lib::KalmanFilterAloamGarm::statecov_t::P
P_t P
State covariance matrix.
Definition: kalman_filter_aloamgarm.h:51
mrs_lib::KalmanFilterAloamGarm::P_t
Eigen::Matrix< double, n, n > P_t
State uncertainty covariance matrix type .
Definition: kalman_filter_aloamgarm.h:39
mrs_lib::KalmanFilterAloamGarm::m
static const int m
Length of the input vector of the system.
Definition: kalman_filter_aloamgarm.h:32
mrs_lib::KalmanFilterAloamGarm::x_t
Eigen::Matrix< double, n, 1 > x_t
State vector type .
Definition: kalman_filter_aloamgarm.h:35