kalman_filter_linear_ord1.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2015 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 #ifndef KALMAN_FILTER_LINEAR_ORD1_H
33 #define KALMAN_FILTER_LINEAR_ORD1_H
34 
36 
37 namespace tuw
38 {
45 template <typename NumType, size_t XDim, size_t UDim, typename ParamType>
46 class KalmanFilterLinOrd1 : public KalmanFilterPredictInterface<NumType, 2 * XDim, UDim, ParamType>
47 {
48 public:
49  KalmanFilterLinOrd1(ParamType& _params)
50  : KalmanFilterPredictInterface<NumType, 2 * XDim, UDim, ParamType>(_params), Ta_(0), recalculate_(false)
51  {
52  this->Phi_.setZero();
53  for (size_t i = 0; i < 2 * XDim; ++i)
54  {
55  this->Phi_(i, i) = 1;
56  }
57  this->f_.setZero();
58  this->Q_.setZero();
59  this->Sigma_.setZero();
61  }
62 
63 public:
64  virtual void computeSigmaInit() override
65  {
66  for (size_t i = 0; i < 2 * XDim; ++i)
67  {
68  this->Sigma_(i, i) = 1000000;
69  }
70  }
71 
72 public:
73  virtual void precompute(const double& _Ta) override
74  {
75  if (_Ta == Ta_)
76  {
77  recalculate_ = true;
78  }
79  else
80  {
81  recalculate_ = true;
82  Ta_ = _Ta;
83  TaSqr_ = Ta_ * Ta_;
84  TaCub_ = TaSqr_ * Ta_;
85  }
86  }
87 
88 public:
89  void computePhi() override
90  {
91  if (recalculate_)
92  {
93  for (size_t i = 0; i < XDim; ++i)
94  {
95  this->Phi_(i, i + XDim) = Ta_;
96  }
97  }
98  }
99 
100 public:
101  void computef(const Eigen::Matrix<NumType, UDim, 1>& _u) override
102  {
103  for (size_t i = 0; i < XDim; ++i)
104  {
105  this->f_(i) = this->x_(i) + this->x_(i + XDim) * Ta_;
106  this->f_(i + XDim) = this->x_(i + XDim);
107  }
108  }
109 
110 public:
111  void computeQ() override
112  {
114  {
115  for (size_t i = 0; i < XDim; ++i)
116  {
117  this->Q_(i, i) = TaCub_ * nn_(i);
118  this->Q_(i, i + XDim) = this->Q_(i + XDim, i) = TaSqr_ * nn_(i);
119  this->Q_(i + XDim, i + XDim) = Ta_ * nn_(i);
120  }
121  recalculateQ_ = false;
122  }
123  }
128 public:
129  void setNN(const size_t& _i, const double& _val)
130  {
131  nn_(_i) = _val;
132  recalculateQ_ = true;
133  }
134 
135 private:
136  Eigen::Matrix<NumType, XDim, 1> nn_;
137 private:
138  double Ta_, TaSqr_, TaCub_;
139 
140 private:
142 
143 private:
145 };
146 }
147 
148 #endif // KALMAN_FILTER_LINEAR_ORD1_H
Eigen::Matrix< NumType, XDim, 1 > f_
State transition function vector
virtual void precompute(const double &_Ta) override
Interface for precomputation function called at the beginning of the prediction step.
Eigen::Matrix< NumType, XDim, 1 > x_
State vector
Eigen::Matrix< NumType, XDim, 1 > nn_
container storing state noise variance values.
virtual void computeSigmaInit() override
Interface for initialization of the state covariance matrix Sigma_.
void setNN(const size_t &_i, const double &_val)
Sets a noise variance parameter.
Interface for simplified manipulation of specialized (Extended) Kalman Filter prediction part...
Eigen::Matrix< NumType, XDim, XDim > Q_
to the state variables
Eigen::Matrix< NumType, XDim, XDim > Sigma_
State covariance matrix
Partial implementation of KalmanFilterPredictInterface for 1st order multivariate (linear) integrator...
void computef(const Eigen::Matrix< NumType, UDim, 1 > &_u) override
Interface for computation of the state transition function vector f_.
void computeQ() override
Interface for computation of the state process noise matrix Q_.
void computePhi() override
Interface for computation of the state transition matrix Phi_.


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:21