kalman.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010, 2011, 2012
3  * Nicolas Mansard,
4  * François Bleibel,
5  * Olivier Stasse,
6  * Florent Lamiraux
7  *
8  * CNRS/AIST
9  *
10  */
11 
12 #ifndef __SOT_KALMAN_H
13 #define __SOT_KALMAN_H
14 
15 /* -------------------------------------------------------------------------- */
16 /* --- INCLUDE -------------------------------------------------------------- */
17 /* -------------------------------------------------------------------------- */
18 
20 #include <dynamic-graph/entity.h>
22 
23 #include <Eigen/LU>
24 
25 /* -------------------------------------------------------------------------- */
26 /* --- API ------------------------------------------------------------------ */
27 /* -------------------------------------------------------------------------- */
28 
29 #if defined(WIN32)
30 #if defined(kalman_EXPORTS)
31 #define SOT_KALMAN_EXPORT __declspec(dllexport)
32 #else
33 #define SOT_KALMAN_EXPORT __declspec(dllimport)
34 #endif
35 #else
36 #define SOT_KALMAN_EXPORT
37 #endif
38 
39 /* -------------------------------------------------------------------------- */
40 /* --- CLASSE --------------------------------------------------------------- */
41 /* -------------------------------------------------------------------------- */
42 
43 namespace dynamicgraph {
44 namespace sot {
45 
47  public:
48  static const std::string CLASS_NAME;
49  virtual const std::string &getClassName(void) const { return CLASS_NAME; }
50 
51  protected:
52  std::size_t size_state;
53  std::size_t size_measure;
54  double dt;
55 
56  public:
62 
65  observationPredictedSIN; // y_pred = h (x_{k|k-1})
68 
71 
72  public:
73  virtual std::string getDocString() const {
74  return "Implementation of extended Kalman filter \n"
75  "\n"
76  " Dynamics of the system: \n"
77  "\n"
78  " x = f (x , u ) + w (state) \n"
79  " k k-1 k-1 k-1 \n"
80  "\n"
81  " y = h (x ) + v (observation)\n"
82  " k k k \n"
83  "\n"
84  " Prediction:\n"
85  "\n"
86  " ^ ^ \n"
87  " x = f (x , u ) (state) \n"
88  " k|k-1 k-1|k-1 k-1 \n"
89  "\n"
90  " T \n"
91  " P = F P F + Q (covariance)\n"
92  " k|k-1 k-1 k-1|k-1 k-1 \n"
93  "\n"
94  " with\n"
95  " \\ \n"
96  " d f ^ \n"
97  " F = --- (x , u ) \n"
98  " k-1 \\ k-1|k-1 k-1 \n"
99  " d x \n"
100  "\n"
101  " \\ \n"
102  " d h ^ \n"
103  " H = --- (x ) \n"
104  " k \\ k-1|k-1 \n"
105  " d x \n"
106 
107  " Update:\n"
108  "\n"
109  " ^ \n"
110  " z = y - h (x ) (innovation)\n"
111  " k k k|k-1 \n"
112  " T \n"
113  " S = H P H + R (innovation covariance)\n"
114  " k k k|k-1 k \n"
115  " T -1 \n"
116  " K = P H S (Kalman gain)\n"
117  " k k|k-1 k k \n"
118  " ^ ^ \n"
119  " x = x + K z (state) \n"
120  " k|k k|k-1 k k \n"
121  "\n"
122  " P =(I - K H ) P \n"
123  " k|k k k k|k-1 \n"
124  "\n"
125  " Signals\n"
126  " - input(vector)::x_pred: state prediction\n"
127  " ^\n"
128  " - input(vector)::y_pred: observation prediction: h (x )\n"
129  " k|k-1\n"
130  " - input(matrix)::F: partial derivative wrt x of f\n"
131  " - input(vector)::y: measure \n"
132  " - input(matrix)::H: partial derivative wrt x of h\n"
133  " - input(matrix)::Q: variance of noise w\n"
134  " k-1\n"
135  " - input(matrix)::R: variance of noise v\n"
136  " k\n"
137  " - output(matrix)::P_pred: variance of prediction\n"
138  " ^\n"
139  " - output(vector)::x_est: state estimation x\n"
140  " k|k\n";
141  }
142 
143  protected:
144  Matrix &computeVarianceUpdate(Matrix &P_k_k, const sigtime_t &time);
145  Vector &computeStateUpdate(Vector &x_est, const sigtime_t &time);
146 
147  void setStateEstimation(const Vector &x0) {
148  stateEstimation_ = x0;
149  stateUpdateSOUT.recompute(0);
150  }
151 
152  void setStateVariance(const Matrix &P0) {
153  stateVariance_ = P0;
154  varianceUpdateSOUT.recompute(0);
155  }
156  // Current state estimation
157  // ^
158  // x
159  // k-1|k-1
161  // Variance of current state estimation
162  // P
163  // k-1|k-1
165 
166  // ^
167  // Innovation: z = y - H x
168  // k k k k|k-1
170 
171  // F P
172  // k-1 k-1|k-1
174 
175  // Variance prediction
176  // P
177  // k|k-1
179 
180  // Innovation covariance
182 
183  // Kalman Gain
185 
186  public:
187  Kalman(const std::string &name);
188  /* --- Entity --- */
189  void display(std::ostream &os) const;
190 };
191 
192 } // namespace sot
193 } // namespace dynamicgraph
194 
200 #endif
dynamicgraph::sot::Kalman
Definition: kalman.hh:46
dynamicgraph::sot::Kalman::stateVariance_
Matrix stateVariance_
Definition: kalman.hh:164
dynamicgraph::sot::Kalman::noiseTransitionSIN
SignalPtr< Matrix, sigtime_t > noiseTransitionSIN
Definition: kalman.hh:60
dynamicgraph::sot::Kalman::innovationSINTERN
SignalTimeDependent< Matrix, sigtime_t > innovationSINTERN
Definition: kalman.hh:70
dynamicgraph::sot::Kalman::size_measure
std::size_t size_measure
Definition: kalman.hh:53
dynamicgraph::sot::Kalman::setStateVariance
void setStateVariance(const Matrix &P0)
Definition: kalman.hh:152
dynamicgraph::SignalPtr< Vector, sigtime_t >
dynamicgraph
dynamicgraph::Entity
dynamicgraph::sot::Kalman::dt
double dt
Definition: kalman.hh:54
dynamicgraph::sot::Kalman::K_
Matrix K_
Definition: kalman.hh:184
dynamicgraph::sot::Kalman::modelTransitionSIN
SignalPtr< Matrix, sigtime_t > modelTransitionSIN
Definition: kalman.hh:58
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::Kalman::S_
Matrix S_
Definition: kalman.hh:181
dynamicgraph::sot::Kalman::observationPredictedSIN
SignalPtr< Vector, sigtime_t > observationPredictedSIN
Definition: kalman.hh:65
dynamicgraph::sot::Kalman::statePredictedSIN
SignalPtr< Vector, sigtime_t > statePredictedSIN
Definition: kalman.hh:63
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::Kalman::noiseMeasureSIN
SignalPtr< Matrix, sigtime_t > noiseMeasureSIN
Definition: kalman.hh:61
dynamicgraph::sot::Kalman::getClassName
virtual const std::string & getClassName(void) const
Definition: kalman.hh:49
SOT_KALMAN_EXPORT
#define SOT_KALMAN_EXPORT
Definition: kalman.hh:36
dynamicgraph::sot::Kalman::Pk_k_1_
Matrix Pk_k_1_
Definition: kalman.hh:178
all-signals.h
display
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::Kalman::CLASS_NAME
static const std::string CLASS_NAME
Definition: kalman.hh:48
dynamicgraph::sot::Kalman::stateEstimation_
Vector stateEstimation_
Definition: kalman.hh:160
linear-algebra.h
dynamicgraph::sot::Kalman::stateUpdateSOUT
SignalTimeDependent< Vector, sigtime_t > stateUpdateSOUT
Definition: kalman.hh:67
dynamicgraph::SignalTimeDependent< Matrix, sigtime_t >
dynamicgraph::sot::Kalman::gainSINTERN
SignalTimeDependent< Matrix, sigtime_t > gainSINTERN
Definition: kalman.hh:69
dynamicgraph::sot::Kalman::FP_
Matrix FP_
Definition: kalman.hh:173
dynamicgraph::sot::Kalman::getDocString
virtual std::string getDocString() const
Definition: kalman.hh:73
x0
x0
dynamicgraph::sot::Kalman::setStateEstimation
void setStateEstimation(const Vector &x0)
Definition: kalman.hh:147
dynamicgraph::sot::Kalman::varianceUpdateSOUT
SignalTimeDependent< Matrix, sigtime_t > varianceUpdateSOUT
Definition: kalman.hh:66
dynamicgraph::sot::Kalman::measureSIN
SignalPtr< Vector, sigtime_t > measureSIN
Definition: kalman.hh:57
dynamicgraph::sot::Kalman::modelMeasureSIN
SignalPtr< Matrix, sigtime_t > modelMeasureSIN
Definition: kalman.hh:59
dynamicgraph::sot::Kalman::z_
Vector z_
Definition: kalman.hh:169
compile.name
name
Definition: compile.py:23
dynamicgraph::sot::Kalman::size_state
std::size_t size_state
Definition: kalman.hh:52


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31