ekfilter.hpp

Go to the documentation of this file.
00001 // This file is part of kfilter.
00002 // kfilter is a C++ variable-dimension extended kalman filter library.
00003 //
00004 // Copyright (C) 2004        Vincent Zalzal, Sylvain Marleau
00005 // Copyright (C) 2001, 2004  Richard Gourdeau
00006 // Copyright (C) 2004        GRPR and DGE's Automation sector
00007 //                           École Polytechnique de Montréal
00008 //
00009 // Code adapted from algorithms presented in :
00010 //      Bierman, G. J. "Factorization Methods for Discrete Sequential
00011 //      Estimation", Academic Press, 1977.
00012 //
00013 // This library is free software; you can redistribute it and/or
00014 // modify it under the terms of the GNU Lesser General Public
00015 // License as published by the Free Software Foundation; either
00016 // version 2.1 of the License, or (at your option) any later version.
00017 //
00018 // This library is distributed in the hope that it will be useful,
00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 // Lesser General Public License for more details.
00022 //
00023 // You should have received a copy of the GNU Lesser General Public
00024 // License along with this library; if not, write to the Free Software
00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027 #ifndef EKFILTER_HPP
00028 #define EKFILTER_HPP
00029 
00032 
00033 #include "kalman/kvector.hpp"
00034 #include "kalman/kmatrix.hpp"
00035 
00036 namespace Kalman {
00037 
00039 
00149   template<typename T, K_UINT_32 BEG, bool OQ = false, 
00150            bool OVR = false, bool DBG = true>
00151   class EKFilter {
00152   public:
00153 
00154     typedef T type;     
00155 
00156     enum { beg = BEG    
00157     };
00158 
00159     typedef KVector<T, BEG, DBG> Vector;  
00160     typedef KMatrix<T, BEG, DBG> Matrix;  
00161 
00163 
00164 
00166     EKFilter();
00167     
00169 
00172     EKFilter(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_, 
00173              K_UINT_32 m_, K_UINT_32 nv_);
00174 
00176     virtual ~EKFilter();
00177 
00179 
00181 
00182 
00184     K_UINT_32 getSizeX() const;
00185 
00187     K_UINT_32 getSizeU() const;
00188 
00190     K_UINT_32 getSizeW() const;
00191 
00193     K_UINT_32 getSizeZ() const;
00194 
00196     K_UINT_32 getSizeV() const;
00197 
00199 
00207 
00208 
00209     // TODO !!! watch out : i don't know which dims can be 0 !
00210 
00212 
00219     void setDim(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_, 
00220                 K_UINT_32 m_, K_UINT_32 nv_);
00221 
00223 
00227     void setSizeX(K_UINT_32 n_);
00228 
00230     void setSizeU(K_UINT_32 nu_);
00231 
00233 
00237     void setSizeW(K_UINT_32 nw_);
00238 
00240     void setSizeZ(K_UINT_32 m_);
00241 
00243     void setSizeV(K_UINT_32 nv_);
00244 
00246 
00248 
00259     void init(Vector& x_, Matrix& P_);
00260 
00270 
00271 
00273 
00289     void step(Vector& u_, const Vector& z_);
00290 
00292 
00300     void timeUpdateStep(Vector& u_);
00301 
00303 
00314     void measureUpdateStep(const Vector& z_);
00315 
00317 
00334     const Vector& predict(Vector& u_);
00335 
00337 
00354     const Vector& simulate();
00355 
00357     const Vector& getX() const;
00358 
00360 
00371     const Matrix& calculateP() const;
00372 
00374 
00375   protected:
00376 
00378 
00389     void NoModification();
00390 
00391     // TODO !!! : watch out for all virtual functions : can dims be 0 ?
00392     
00415 
00416 
00418     virtual void makeBaseA();
00419 
00421     virtual void makeBaseW();
00422 
00424 
00428     virtual void makeBaseQ();
00429 
00431     virtual void makeBaseH();
00432 
00434 
00439     virtual void makeBaseV();
00440 
00442 
00447     virtual void makeBaseR();
00448 
00450 
00479 
00480 
00482 
00492     virtual void makeCommonProcess();
00493 
00495     virtual void makeA();
00496 
00498     virtual void makeW();
00499 
00501 
00505     virtual void makeQ();
00506 
00508 
00515     virtual void makeProcess() = 0;
00516     
00518 
00528     virtual void makeCommonMeasure();
00529 
00531     virtual void makeH();
00532 
00534 
00539     virtual void makeV();
00540 
00542 
00547     virtual void makeR();
00548 
00550 
00559     virtual void makeMeasure() = 0;
00560 
00562 
00569     virtual void makeDZ();
00570 
00572 
00574 
00579     virtual void sizeUpdate();
00580 
00582 
00583 
00586     Vector x;           
00587 
00590     Vector u;           
00591 
00594     Vector z;           
00595 
00599     Vector dz;          
00600 
00606     Matrix A;           
00607 
00613     Matrix W;           
00614 
00622     Matrix Q;           
00623 
00629     Matrix H;           
00630 
00638     Matrix V;           
00639 
00647     Matrix R;           
00648 
00650 
00655 
00656 
00657     K_UINT_32 n;        
00658     K_UINT_32 nu;       
00659     K_UINT_32 nw;       
00660     K_UINT_32  m;       
00661     K_UINT_32 nv;       
00662 
00664 
00665   private:
00666     
00668 
00676     static void factor(Matrix& P_);
00677 
00679 
00685     static void upperInvert(Matrix& P_);
00686 
00688 
00692     void timeUpdate();
00693 
00695 
00702     void measureUpdate(T dz, T r);
00703 
00709 
00710 
00712     void makeBaseAImpl();
00713 
00715     void makeBaseWImpl();
00716 
00718     void makeBaseQImpl();
00719 
00721     void makeBaseHImpl();
00722 
00724     void makeBaseVImpl();
00725 
00727     void makeBaseRImpl();
00728 
00730     void makeAImpl();
00731 
00733     void makeWImpl();
00734 
00736     void makeQImpl();
00737 
00739     void makeHImpl();
00740 
00742     void makeVImpl();
00743 
00745     void makeRImpl();
00746 
00748 
00759     Matrix U;           
00760 
00765     Matrix W_;          
00766 
00771     Matrix Q_;          
00772 
00781     Matrix H_;          
00782 
00795     Matrix R_;          
00796 
00797     Vector a;           
00798     Vector d;           
00799     Vector v;           
00800 
00803     K_UINT_32 nn;       
00804 
00805     mutable Matrix _P;  
00806     mutable Vector _x;  
00807 
00808     K_UINT_16 flags;    
00809     bool modified_;     
00810 
00811   };
00812 
00813 }
00814 
00815 #include "kalman/ekfilter_impl.hpp"
00816 
00817 #endif
00818 
01089 

Generated on Sat Jan 28 21:02:01 2006 for KFilter by  doxygen 1.4.5