Robotics Library  0.6.2
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 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_MATH_KALMAN_H_
28 #define _RL_MATH_KALMAN_H_
29 
30 #include <Eigen/LU>
31 
32 #include "Matrix.h"
33 #include "Vector.h"
34 
35 namespace rl
36 {
37  namespace math
38  {
39  class Kalman
40  {
41  public:
43  {
44  };
45 
46  virtual ~Kalman()
47  {
48  };
49 
63  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Vector6, typename Matrix7 >
64  static void correct(
65  const Vector1& xPrior,
66  const Matrix2& pPrior,
67  const Matrix3& h,
68  const Matrix4& r,
69  const Vector5& z,
70  Vector6& xPost,
71  Matrix7& pPost
72  )
73  {
74  // \f[ K_{k} = P^{-}_{k} H^{T} \left( H P^{-}_{k} H^{T} + R \right)^{-1} \f]
75  Matrix k = pPrior * h.transpose() * (h * pPrior * h.transpose() + r).inverse();
76  // \f[ \hat{x}_{k} = \hat{x}^{-}_{k} + K_{k} \left( z_{k} - H \hat{x}^{-}_{k} \right) \f]
77  xPost = xPrior + k * (z - h * xPrior);
78  // P_{k} = \left( I - K_{k} H \right) P^{-}_{k} \f]
79  pPost = (Matrix::Identity(k.rows(), h.cols()) - k * h) * pPrior;
80  }
81 
93  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Matrix6 >
94  static void predict(
95  const Vector1& xPost,
96  const Matrix2& pPost,
97  const Matrix3& a,
98  const Matrix4& q,
99  Vector5& xPrior,
100  Matrix6& pPrior
101  )
102  {
103  // \f[ \hat{x}^{-}_{k} = A \hat{x}_{k - 1} \f]
104  xPrior = a * xPost;
105  // \f[ P^{-}_{k} = A P_{k - 1} A^{T} + Q \f]
106  pPrior = a * pPost * a.transpose() + q;
107  }
108 
122  template< typename Vector1, typename Matrix2, typename Matrix3, typename Matrix4, typename Vector5, typename Matrix6, typename Vector7, typename Matrix8 >
123  static void predict(
124  const Vector1& xPost,
125  const Matrix2& pPost,
126  const Matrix3& a,
127  const Matrix4& b,
128  const Vector5& u,
129  const Matrix6& q,
130  Vector7& xPrior,
131  Matrix8& pPrior
132  )
133  {
134  // \f[ \hat{x}^{-}_{k} = A \hat{x}_{k - 1} + B u_{k - 1} \f]
135  xPrior = a * xPost + b * u;
136  // \f[ P^{-}_{k} = A P_{k - 1} A^{T} + Q \f]
137  pPrior = a * pPost * a.transpose() + q;
138  }
139 
140  protected:
141 
142  private:
143 
144  };
145  }
146 }
147 
148 #endif // _RL_MATH_KALMAN_H_
rl::math::Kalman::predict
static void predict(const Vector1 &xPost, const Matrix2 &pPost, const Matrix3 &a, const Matrix4 &q, Vector5 &xPrior, Matrix6 &pPrior)
Definition: Kalman.h:94
rl::math::Kalman::Kalman
Kalman()
Definition: Kalman.h:42
Vector.h
rl::math::Kalman::~Kalman
virtual ~Kalman()
Definition: Kalman.h:46
rl::math::Kalman::predict
static void predict(const Vector1 &xPost, const Matrix2 &pPost, const Matrix3 &a, const Matrix4 &b, const Vector5 &u, const Matrix6 &q, Vector7 &xPrior, Matrix8 &pPrior)
Definition: Kalman.h:123
rl::math::Vector6
::Eigen::Matrix< Real, 6, 1 > Vector6
Definition: Vector.h:49
rl::math::Kalman::correct
static void correct(const Vector1 &xPrior, const Matrix2 &pPrior, const Matrix3 &h, const Matrix4 &r, const Vector5 &z, Vector6 &xPost, Matrix7 &pPost)
Definition: Kalman.h:64
rl::math::Matrix
::Eigen::Matrix< Real, ::Eigen::Dynamic, ::Eigen::Dynamic > Matrix
Definition: Matrix.h:41
Matrix.h
rl::math::Kalman
Definition: Kalman.h:40
rl
Definition: Ati.cpp:35