Kalman.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef KALMAN_H
25 #define KALMAN_H
26 
33 #include "Alvar.h"
34 #include "cxcore.h"
35 
36 namespace alvar {
37 
40  friend class KalmanVisualize;
41 protected:
42  int n;
43  int m;
44  CvMat *H_trans;
45  CvMat *z_pred;
46  CvMat *z_residual;
47  CvMat *x_gain;
48 public:
50  CvMat *z;
52  CvMat *H;
56  CvMat *K;
64  KalmanSensorCore(int _n, int _m);
68  int get_n() { return n; }
70  int get_m() { return m; }
76  virtual void update_x(CvMat *x_pred, CvMat *x);
77 };
78 
81  friend class KalmanVisualize;
82 protected:
83  int n;
84  //CvMat *x_pred;
85  CvMat *F_trans;
86  virtual void predict_x(unsigned long tick);
87 public:
89  CvMat *x;
91  CvMat *F;
93  KalmanCore(const KalmanCore &s);
98  KalmanCore(int _n);
100  ~KalmanCore();
102  int get_n() { return n; }
106  virtual CvMat *predict();
110  CvMat *predict_update(KalmanSensorCore *sensor);
111 
113  CvMat *x_pred;
114 
115 };
116 
119 protected:
120  CvMat *R_tmp;
121  CvMat *P_tmp;
122 public:
124  CvMat *R;
126  KalmanSensor(const KalmanSensor &k);
132  KalmanSensor(int n, int _m);
134  ~KalmanSensor();
139  virtual void update_H(CvMat *x_pred) {}
143  virtual void update_K(CvMat *P_pred);
147  virtual void update_P(CvMat *P_pred, CvMat *P);
148 };
149 
179 protected:
180  int prev_tick;
181  void predict_P();
182 public:
184  CvMat *P;
186  CvMat *Q;
188  CvMat *P_pred;
194  Kalman(int _n);
196  ~Kalman();
200  virtual void update_F(unsigned long tick);
207  CvMat *predict(unsigned long tick);
214  CvMat *predict_update(KalmanSensor *sensor, unsigned long tick);
216  double seconds_since_update(unsigned long tick);
217 };
218 
226 protected:
227  CvMat *delta;
228  CvMat *x_plus;
229  CvMat *x_minus;
230  CvMat *z_tmp1;
231  CvMat *z_tmp2;
232  virtual void h(CvMat *x_pred, CvMat *_z_pred) = 0;
233  virtual void update_H(CvMat *x_pred);
234  virtual void update_x(CvMat *x_pred, CvMat *x);
235 public:
237  KalmanSensorEkf(int _n, int _m);
238  ~KalmanSensorEkf();
239 };
240 
247 class ALVAR_EXPORT KalmanEkf : public Kalman {
248 protected:
249  CvMat *delta;
250  CvMat *x_plus;
251  CvMat *x_minus;
252  CvMat *x_tmp1;
253  CvMat *x_tmp2;
254  virtual void f(CvMat *_x, CvMat *_x_pred, double dt) = 0;
255  virtual void update_F(unsigned long tick);
256  virtual void predict_x(unsigned long tick);
257 public:
258  KalmanEkf(int _n);
259  ~KalmanEkf();
260 };
261 
275  int n;
276  int m;
282  IplImage *img;
284  IplImage *img_legend;
286  IplImage *img_show;
290  void img_matrix(CvMat *mat, int top, int left);
292  void Init();
293 public:
295  static void out_matrix(CvMat *m, char *name);
297  KalmanVisualize(Kalman *_kalman, KalmanSensor *_sensor);
299  KalmanVisualize(KalmanCore *_kalman, KalmanSensorCore *_sensor);
301  ~KalmanVisualize();
303  void update_pre();
305  void update_post();
307  void show();
308 };
309 
310 } // namespace alvar
311 
312 #endif
Extended Kalman Filter (EKF) sensor implementation.
Definition: Kalman.h:225
Main ALVAR namespace.
Definition: Alvar.h:174
CvMat * x_tmp1
Definition: Kalman.h:252
f
Extended Kalman Filter (EKF) implementation.
Definition: Kalman.h:247
Core implementation for Kalman.
Definition: Kalman.h:80
int prev_tick
Definition: Kalman.h:180
CvMat * x_plus
Definition: Kalman.h:250
KalmanSensorCore * sensor
Definition: Kalman.h:278
Class for visualizing Kalman filter.
Definition: Kalman.h:274
CvMat * K
The matrix (n*m) containing Kalman gain (something between 0 and H^-1). In this core-implementation w...
Definition: Kalman.h:56
CvMat * P
The error covariance matrix describing the accuracy of the state estimate.
Definition: Kalman.h:184
int get_n()
Accessor for n.
Definition: Kalman.h:68
void ALVAR_EXPORT out_matrix(const CvMat *m, const char *name)
Output OpenCV matrix for debug purposes.
Definition: Util.cpp:216
CvMat * P_pred
The predicted error covariance matrix.
Definition: Kalman.h:188
IplImage * img_show
Image to show.
Definition: Kalman.h:286
Core implementation for Kalman sensor.
Definition: Kalman.h:39
IplImage * img_legend
Image to show.
Definition: Kalman.h:284
CvMat * R
The covariance matrix for the observation noise.
Definition: Kalman.h:124
CvMat * delta
Definition: Kalman.h:249
Kalman sensor implementation.
Definition: Kalman.h:118
KalmanCore * kalman
Definition: Kalman.h:277
int get_m()
Accessor for m.
Definition: Kalman.h:70
CvMat * F_trans
Definition: Kalman.h:85
CvMat * x_minus
Definition: Kalman.h:251
TFSIMD_FORCE_INLINE const tfScalar & x() const
CvMat * H
The matrix (m*n) mapping Kalman state vector into this sensor&#39;s measurements vector.
Definition: Kalman.h:52
CvMat * x_tmp2
Definition: Kalman.h:253
CvMat * F
The matrix (n*n) containing the transition model for the internal state.
Definition: Kalman.h:91
#define ALVAR_EXPORT
Definition: Alvar.h:168
CvMat * x_pred
Predicted state, TODO: should be protected?!
Definition: Kalman.h:113
CvMat * Q
The covariance matrix for the process noise.
Definition: Kalman.h:186
CvMat * z
Latest measurement vector (m*1)
Definition: Kalman.h:50
CvMat * x
The Kalman state vector (n*1)
Definition: Kalman.h:89
IplImage * img
Image collecting visualization of the Kalman filter.
Definition: Kalman.h:282
KalmanSensor * sensor_ext
Definition: Kalman.h:280
int img_scale
visualization scale before show
Definition: Kalman.h:288
int get_n()
Accessor for n.
Definition: Kalman.h:102
virtual void update_H(CvMat *x_pred)
Method for updating how the Kalman state vector is mapped into this sensor&#39;s measurements vector...
Definition: Kalman.h:139
This file defines library export definitions, version numbers and build information.
Kalman implementation.
Definition: Kalman.h:178
Kalman * kalman_ext
Definition: Kalman.h:279


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04