kalman-cpp
Implementation of Kalman Filter in C++
ekf.h
Go to the documentation of this file.
1 
21 #ifndef EKF_H
22 #define EKF_H
23 
24 #define _USE_MATH_DEFINES
25 #include <math.h>
26 
27 #include <assert.h>
28 #include <armadillo>
29 
30 using namespace std;
31 using namespace arma;
32 
37 class EKF {
38 public:
42  EKF();
43 
47  ~EKF();
48 
56  void InitSystem(int n_states, int n_outputs, const mat& Q, const mat& R);
62  virtual colvec f(const colvec &x, const colvec &u);
63 
68  virtual colvec h(const colvec &x);
75  void InitSystemState(const colvec& x0);
76 
83  void InitSystemStateCovariance(const mat& P0);
84 
90  void EKalmanf(const colvec& u);
91 
100  void EKalmanf(const colvec& z, const colvec& u);
101 
106  colvec* GetCurrentState();
107 
113  colvec* GetCurrentOutput();
114 
120  colvec* GetCurrentEstimatedState();
121 
126  colvec* GetCurrentEstimatedOutput();
127 
128 private:
135  void CalcF(const colvec &x, const colvec &u);
136 
142  void CalcH(const colvec &x);
143 
144  mat F_;
145  mat H_;
146  mat Q_;
147  mat R_;
148  colvec v_;
149  colvec w_;
150 
151  mat sqrt_Q_;
152  mat sqrt_R_;
153 
154 
155 
156  colvec x_m_;
157  colvec x_p_;
158 
159  mat P_p_;
160  mat P_m_;
161 
162  colvec z_m_;
163 
164  double epsilon_;
165 
166 protected:
167 
168  int nStates_;
169  int nOutputs_;
170 
171  colvec x_;
172  colvec z_;
173 };
174 
175 
176 #endif
Implemetation of the extended Kalman filter. This class needs to be derived.
Definition: ekf.h:37
colvec * GetCurrentEstimatedOutput()
Get current estimated output.
Definition: ekf.cpp:186
void EKalmanf(const colvec &u)
Do the extended Kalman iteration step-by-step while simulating the system. Simulating the system is d...
Definition: ekf.cpp:125
colvec x_
State vector.
Definition: ekf.h:171
void InitSystemState(const colvec &x0)
Initialize the system states. Must be called after InitSystem. If not called, system state is initial...
Definition: ekf.cpp:111
colvec z_
Output matrix.
Definition: ekf.h:172
void InitSystemStateCovariance(const mat &P0)
Initialize the system state covariance. Must be called after InitSystem. If not called,...
Definition: ekf.cpp:118
virtual colvec f(const colvec &x, const colvec &u)
Define model of your system.
Definition: ekf.cpp:60
int nOutputs_
Number of outputs.
Definition: ekf.h:169
colvec * GetCurrentOutput()
Get current simulated true output. This is analogous to the measurements.
Definition: ekf.cpp:175
void InitSystem(int n_states, int n_outputs, const mat &Q, const mat &R)
Tell me how many states and outputs you have!
Definition: ekf.cpp:20
EKF()
Constructor, nothing happens here.
Definition: ekf.cpp:10
~EKF()
Destructur, nothing happens here.
Definition: ekf.cpp:15
virtual colvec h(const colvec &x)
Define the output model of your system.
Definition: ekf.cpp:67
colvec * GetCurrentEstimatedState()
Get current estimated state. This is analogous to the filtered measurements.
Definition: ekf.cpp:180
int nStates_
Number of the states.
Definition: ekf.h:168
colvec * GetCurrentState()
Get current simulated true state.
Definition: ekf.cpp:170