kalman-cpp
Implementation of Kalman Filter in C++
ukf.h
Go to the documentation of this file.
1 
26 #ifndef EKF_H
27 #define EKF_H
28 
29 #define _USE_MATH_DEFINES
30 #include <math.h>
31 
32 #include <assert.h>
33 #include <armadillo>
34 
35 using namespace std;
36 using namespace arma;
37 
42 class UKF {
43 public:
47  UKF();
48 
52  ~UKF();
53 
61  void InitSystem(int n_states, int n_outputs, const mat& Q, const mat& R);
67  virtual colvec f(const colvec &x, const colvec &u);
68 
73  virtual colvec h(const colvec &x);
80  void InitSystemState(const colvec& x0);
81 
88  void InitSystemStateCovariance(const mat& P0);
89 
95  void UKalmanf(const colvec& u);
96 
105  void UKalmanf(const colvec& z, const colvec& u);
106 
111  colvec* GetCurrentState();
112 
118  colvec* GetCurrentOutput();
119 
125  colvec* GetCurrentEstimatedState();
126 
131  colvec* GetCurrentEstimatedOutput();
132 
133 private:
134 
135  mat Q_;
136  mat R_;
137  colvec v_;
138  colvec w_;
139 
140  mat sqrt_Q_;
141  mat sqrt_R_;
142 
143  mat P_;
144  colvec x_m_;
145  colvec z_m_;
146 
147 protected:
148 
149  int nStates_;
150  int nOutputs_;
151 
152  colvec x_;
153  colvec z_;
154 };
155 
156 
157 #endif
Implemetation of the Unscented Kalman filter. This class needs to be derived.
Definition: ukf.h:42
colvec * GetCurrentEstimatedOutput()
Get current estimated output.
Definition: ukf.cpp:229
virtual colvec f(const colvec &x, const colvec &u)
Define model of your system.
Definition: ukf.cpp:57
void UKalmanf(const colvec &u)
Do the extended Kalman iteration step-by-step while simulating the system. Simulating the system is d...
Definition: ukf.cpp:87
colvec * GetCurrentState()
Get current simulated true state.
Definition: ukf.cpp:213
colvec * GetCurrentOutput()
Get current simulated true output. This is analogous to the measurements.
Definition: ukf.cpp:218
colvec z_
Output matrix, by simulation, true value.
Definition: ukf.h:153
void InitSystem(int n_states, int n_outputs, const mat &Q, const mat &R)
Tell me how many states and outputs you have!
Definition: ukf.cpp:20
int nStates_
Number of the states.
Definition: ukf.h:149
UKF()
Constructor, nothing happens here.
Definition: ukf.cpp:10
void InitSystemStateCovariance(const mat &P0)
Initialize the system state covariance. Must be called after InitSystem. If not called,...
Definition: ukf.cpp:79
int nOutputs_
Number of outputs.
Definition: ukf.h:150
colvec * GetCurrentEstimatedState()
Get current estimated state. This is analogous to the filtered measurements.
Definition: ukf.cpp:223
virtual colvec h(const colvec &x)
Define the output model of your system.
Definition: ukf.cpp:64
colvec x_
State vector, by simulaiton, true value.
Definition: ukf.h:152
void InitSystemState(const colvec &x0)
Initialize the system states. Must be called after InitSystem. If not called, system state is initial...
Definition: ukf.cpp:71
~UKF()
Destructur, nothing happens here.
Definition: ukf.cpp:15