Robotics Library  0.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Kalman.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Technische Universitaet Muenchen nor the names of
14 // its contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef _RL_MATH_KALMAN_H_
31 #define _RL_MATH_KALMAN_H_
32 
33 #include <Eigen/LU>
34 
35 #include "Matrix.h"
36 #include "Vector.h"
37 
38 namespace rl
39 {
40  namespace math
41  {
42  class Kalman
43  {
44  public:
46  {
47  };
48 
49  virtual ~Kalman()
50  {
51  };
52 
66  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Vector6, typename Matrix7 >
67  static void correct(
68  const Vector1& xPrior,
69  const Matrix2& pPrior,
70  const Matrix3& h,
71  const Matrix4& r,
72  const Vector5& z,
73  Vector6& xPost,
74  Matrix7& pPost
75  )
76  {
77  // \f[ K_{k} = P^{-}_{k} H^{T} \left( H P^{-}_{k} H^{T} + R \right)^{-1} \f]
78  Matrix k = pPrior * h.transpose() * (h * pPrior * h.transpose() + r).inverse();
79  // \f[ \hat{x}_{k} = \hat{x}^{-}_{k} + K_{k} \left( z_{k} - H \hat{x}^{-}_{k} \right) \f]
80  xPost = xPrior + k * (z - h * xPrior);
81  // P_{k} = \left( I - K_{k} H \right) P^{-}_{k} \f]
82  pPost = (Matrix::Identity(k.rows(), h.cols()) - k * h) * pPrior;
83  }
84 
96  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Matrix6 >
97  static void predict(
98  const Vector1& xPost,
99  const Matrix2& pPost,
100  const Matrix3& a,
101  const Matrix4& q,
102  Vector5& xPrior,
103  Matrix6& pPrior
104  )
105  {
106  // \f[ \hat{x}^{-}_{k} = A \hat{x}_{k - 1} \f]
107  xPrior = a * xPost;
108  // \f[ P^{-}_{k} = A P_{k - 1} A^{T} + Q \f]
109  pPrior = a * pPost * a.transpose() + q;
110  }
111 
125  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Matrix6, typename Vector7, typename Matrix8 >
126  static void predict(
127  const Vector1& xPost,
128  const Matrix2& pPost,
129  const Matrix3& a,
130  const Matrix4& b,
131  const Vector5& u,
132  const Matrix6& q,
133  Vector7& xPrior,
134  Matrix8& pPrior
135  )
136  {
137  // \f[ \hat{x}^{-}_{k} = A \hat{x}_{k - 1} + B u_{k - 1} \f]
138  xPrior = a * xPost + b * u;
139  // \f[ P^{-}_{k} = A P_{k - 1} A^{T} + Q \f]
140  pPrior = a * pPost * a.transpose() + q;
141  }
142 
143  protected:
144 
145  private:
146 
147  };
148  }
149 }
150 
151 #endif // _RL_MATH_KALMAN_H_