ekfilter.hpp
Go to the documentation of this file.
1 // This file is part of kfilter.
2 // kfilter is a C++ variable-dimension extended kalman filter library.
3 //
4 // Copyright (C) 2004 Vincent Zalzal, Sylvain Marleau
5 // Copyright (C) 2001, 2004 Richard Gourdeau
6 // Copyright (C) 2004 GRPR and DGE's Automation sector
7 // École Polytechnique de Montréal
8 //
9 // Code adapted from algorithms presented in :
10 // Bierman, G. J. "Factorization Methods for Discrete Sequential
11 // Estimation", Academic Press, 1977.
12 //
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 
27 #ifndef EKFILTER_HPP
28 #define EKFILTER_HPP
29 
32 
33 #include <kfilter/kvector.hpp>
34 #include <kfilter/kmatrix.hpp>
35 
36 namespace Kalman {
37 
39 
149  template<typename T, K_UINT_32 BEG, bool OQ = false,
150  bool OVR = false, bool DBG = true>
151  class EKFilter {
152  public:
153 
154  typedef T type;
155 
156  enum { beg = BEG
157  };
158 
161 
163 
164 
166  EKFilter();
167 
169 
172  EKFilter(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_,
173  K_UINT_32 m_, K_UINT_32 nv_);
174 
176  virtual ~EKFilter();
177 
179 
181 
182 
184  K_UINT_32 getSizeX() const;
185 
187  K_UINT_32 getSizeU() const;
188 
190  K_UINT_32 getSizeW() const;
191 
193  K_UINT_32 getSizeZ() const;
194 
196  K_UINT_32 getSizeV() const;
197 
199 
207 
208 
209  // TODO !!! watch out : i don't know which dims can be 0 !
210 
212 
219  void setDim(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_,
220  K_UINT_32 m_, K_UINT_32 nv_);
221 
223 
227  void setSizeX(K_UINT_32 n_);
228 
230  void setSizeU(K_UINT_32 nu_);
231 
233 
237  void setSizeW(K_UINT_32 nw_);
238 
240  void setSizeZ(K_UINT_32 m_);
241 
243  void setSizeV(K_UINT_32 nv_);
244 
246 
248 
259  void init(Vector& x_, Matrix& P_);
260 
270 
271 
273 
289  void step(Vector& u_, const Vector& z_);
290 
292 
300  void timeUpdateStep(Vector& u_);
301 
303 
314  void measureUpdateStep(const Vector& z_);
315 
317 
334  const Vector& predict(Vector& u_);
335 
337 
354  const Vector& simulate();
355 
357  const Vector& getX() const;
358 
360 
371  const Matrix& calculateP() const;
372 
374 
375  protected:
376 
378 
389  void NoModification();
390 
391  // TODO !!! : watch out for all virtual functions : can dims be 0 ?
392 
415 
416 
418  virtual void makeBaseA();
419 
421  virtual void makeBaseW();
422 
424 
428  virtual void makeBaseQ();
429 
431  virtual void makeBaseH();
432 
434 
439  virtual void makeBaseV();
440 
442 
447  virtual void makeBaseR();
448 
450 
479 
480 
482 
492  virtual void makeCommonProcess();
493 
495  virtual void makeA();
496 
498  virtual void makeW();
499 
501 
505  virtual void makeQ();
506 
508 
515  virtual void makeProcess() = 0;
516 
518 
528  virtual void makeCommonMeasure();
529 
531  virtual void makeH();
532 
534 
539  virtual void makeV();
540 
542 
547  virtual void makeR();
548 
550 
559  virtual void makeMeasure() = 0;
560 
562 
569  virtual void makeDZ();
570 
572 
574 
579  virtual void sizeUpdate();
580 
582 
583 
587 
591 
595 
600 
607 
614 
623 
630 
639 
648 
650 
655 
656 
662 
664 
665  private:
666 
668 
676  static void factor(Matrix& P_);
677 
679 
685  static void upperInvert(Matrix& P_);
686 
688 
692  void timeUpdate();
693 
695 
702  void measureUpdate(T dz, T r);
703 
709 
710 
712  void makeBaseAImpl();
713 
715  void makeBaseWImpl();
716 
718  void makeBaseQImpl();
719 
721  void makeBaseHImpl();
722 
724  void makeBaseVImpl();
725 
727  void makeBaseRImpl();
728 
730  void makeAImpl();
731 
733  void makeWImpl();
734 
736  void makeQImpl();
737 
739  void makeHImpl();
740 
742  void makeVImpl();
743 
745  void makeRImpl();
746 
748 
760 
766 
772 
782 
796 
800 
804 
805  mutable Matrix _P;
806  mutable Vector _x;
807 
809  bool modified_;
810 
811  };
812 
813 }
814 
815 #include <kfilter/ekfilter_impl.hpp>
816 
817 #endif
818 
virtual void makeMeasure()=0
Actual measurement function . Fills in z.
Matrix Q_
Modified version of Q to whiten process noise.
Definition: ekfilter.hpp:771
void setSizeZ(K_UINT_32 m_)
Sets the size of the measurement vector.
K_UINT_32 getSizeU() const
Returns the size of the input vector.
Generic Extended Kalman Filter (EKF) template base class.
Definition: ekfilter.hpp:151
Matrix Q
Process noise covariance matrix.
Definition: ekfilter.hpp:622
const Matrix & calculateP() const
Returns the a posteriori error covariance estimate matrix.
virtual void makeR()
Virtual creator of R.
void makeBaseWImpl()
makeBaseW() template method.
void makeBaseRImpl()
makeBaseR() template method.
virtual void makeBaseV()
Virtual pre-creator of V.
Matrix H_
Modified version of H to whiten measure noise.
Definition: ekfilter.hpp:781
virtual void makeBaseA()
Virtual pre-creator of A.
void makeVImpl()
makeV() template method.
Minimalist vector template class.
Definition: kvector.hpp:72
virtual void makeW()
Virtual creator of W.
virtual ~EKFilter()
Virtual destructor.
void measureUpdate(T dz, T r)
U-D convariance factorization update.
virtual void makeQ()
Virtual creator of Q.
K_UINT_32 getSizeW() const
Returns the size of the process noise vector.
Vector dz
Innovation vector.
Definition: ekfilter.hpp:599
EKFilter()
Default constructor.
const Vector & predict(Vector &u_)
Returns the predicted state vector (a priori state estimate).
void makeAImpl()
makeA() template method.
Matrix U
Cholesky factorization of P.
Definition: ekfilter.hpp:759
K_UINT_16 flags
Temporary vector.
Definition: ekfilter.hpp:808
void makeBaseQImpl()
makeBaseQ() template method.
virtual void makeProcess()=0
Actual process . Fills in new x by using old x.
K_UINT_32 getSizeV() const
Returns the size of the measurement noise vector.
K_UINT_32 getSizeX() const
Returns the size of the state vector.
Matrix A
A jacobian matrix.
Definition: ekfilter.hpp:606
Vector u
Input vector.
Definition: ekfilter.hpp:590
Matrix _P
Temporary matrix.
Definition: ekfilter.hpp:805
Matrix W
A jacobian matrix.
Definition: ekfilter.hpp:613
void makeQImpl()
makeQ() template method.
K_UINT_32 nv
Size of the measurement noise vector.
Definition: ekfilter.hpp:661
Vector x
Corrected state vector.
Definition: ekfilter.hpp:586
void step(Vector &u_, const Vector &z_)
Makes one prediction-correction step.
virtual void makeV()
Virtual creator of V.
void makeBaseAImpl()
makeBaseA() template method.
void makeBaseVImpl()
makeBaseV() template method.
KVector< T, BEG, DBG > Vector
Vector type.
Definition: ekfilter.hpp:159
Contains the interface of the KMatrix template class.
Matrix V
A jacobian matrix.
Definition: ekfilter.hpp:638
virtual void sizeUpdate()
Resizes all vector and matrices. Never call or overload this !
static void upperInvert(Matrix &P_)
Inplace upper triangular matrix inversion.
Matrix R
Measurement noise covariance matrix.
Definition: ekfilter.hpp:647
virtual void makeBaseH()
Virtual pre-creator of H.
Vector v
Temporary vector.
Definition: ekfilter.hpp:799
void init(Vector &x_, Matrix &P_)
Sets initial conditions for the Kalman Filter.
virtual void makeDZ()
Hook-up function to modify innovation vector.
void NoModification()
Allows optimizations on some calculations.
void setSizeV(K_UINT_32 nv_)
Sets the size of the measurement noise vector.
virtual void makeBaseQ()
Virtual pre-creator of Q.
void setSizeX(K_UINT_32 n_)
Sets the size of the state vector.
static void factor(Matrix &P_)
Inplace upper triangular matrix Cholesky (UDU) factorization.
Starting index of matrices and vectors.
Definition: ekfilter.hpp:156
Contains the implementation of the EKFilter base template class.
void setSizeW(K_UINT_32 nw_)
Sets the size of the process noise vector.
const Vector & simulate()
Returns the predicted measurement vector.
K_UINT_32 getSizeZ() const
Returns the size of the measurement vector.
unsigned short int K_UINT_16
Unsigned 16-bits integral type.
Definition: ktypes.hpp:66
K_UINT_32 nu
Size of the input vector.
Definition: ekfilter.hpp:658
virtual void makeCommonProcess()
Optional function used to precalculate common values for process.
T type
Type of objects contained in matrices and vectors.
Definition: ekfilter.hpp:154
Matrix H
A jacobian matrix.
Definition: ekfilter.hpp:629
unsigned long int K_UINT_32
Unsigned 32-bits integral type.
Definition: ktypes.hpp:68
K_UINT_32 nn
Number of columns of U.
Definition: ekfilter.hpp:803
void timeUpdateStep(Vector &u_)
Makes one prediction step.
void makeHImpl()
makeH() template method.
const Vector & getX() const
Returns the corrected state (a posteriori state estimate).
virtual void makeCommonMeasure()
Optional function used to precalculate common values for measurement.
virtual void makeBaseW()
Virtual pre-creator of W.
Vector d
Temporary vector.
Definition: ekfilter.hpp:798
void makeWImpl()
makeW() template method.
Minimalist matrix template class.
Definition: kmatrix.hpp:72
Vector a
Temporary vector.
Definition: ekfilter.hpp:797
virtual void makeA()
Virtual creator of A.
K_UINT_32 n
Size of the state vector.
Definition: ekfilter.hpp:657
void measureUpdateStep(const Vector &z_)
Makes one correction step.
K_UINT_32 m
Size of the measurement vector.
Definition: ekfilter.hpp:660
void timeUpdate()
MWG-S orthogonalization algorithm for U-D time update.
void setSizeU(K_UINT_32 nu_)
Sets the size of the input vector.
KMatrix< T, BEG, DBG > Matrix
Matrix type.
Definition: ekfilter.hpp:160
Matrix R_
Modified version of R to whiten measure noise.
Definition: ekfilter.hpp:795
void makeBaseHImpl()
makeBaseH() template method.
void setDim(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_, K_UINT_32 m_, K_UINT_32 nv_)
Sets all dimensions at once.
virtual void makeBaseR()
Virtual pre-creator of R.
K_UINT_32 nw
Size of the process noise vector.
Definition: ekfilter.hpp:659
virtual void makeH()
Virtual creator of H.
void makeRImpl()
makeR() template method.
Vector z
Predicted measurement vector.
Definition: ekfilter.hpp:594
Matrix W_
Modified version of W to whiten process noise.
Definition: ekfilter.hpp:765
Contains the interface of the KVector template class.
bool modified_
Boolean flag used by NoModification().
Definition: ekfilter.hpp:809


kfilter
Author(s): Jorge Almeida, Vincent Zalzal, Sylvain Marleau, Richard Gourdeau
autogenerated on Mon Mar 2 2015 01:31:45