UnscentedKalmanFilter.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ROBDEKON
17  * @author Christoph Pohl ( christoph dot pohl at kit dot edu )
18  * @date 16.03.21
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  *
22  * Code adapted to C++ from: https://github.com/CAOR-MINES-ParisTech/ukfm
23  * See also:
24  * - https://arxiv.org/pdf/2002.00878.pdf
25  * - https://ieeexplore.ieee.org/document/8206066/
26  */
27 
28 #ifndef ROBDEKON_UNSCENTEDKALMANFILTER_H
29 #define ROBDEKON_UNSCENTEDKALMANFILTER_H
30 
31 #include <Eigen/Dense>
32 
33 #include "SystemModel.h"
34 
35 template <typename SystemModelT>
37 {
38 public:
39  using FloatT = typename SystemModelT::FloatT;
40  static constexpr float eps = 10 * std::numeric_limits<float>::epsilon();
41  // variable dimensions:
42  using dim = typename SystemModelT::dim;
43  using StateT = typename SystemModelT::StateT;
44  using ControlT = typename SystemModelT::ControlT;
45  using ControlNoiseT =
46  typename SystemModelT::ControlNoiseT; // todo: correct name? Is it the same as ControlT?
47  using SigmaPointsT = typename SystemModelT::SigmaPointsT; // todo: rename
48 
54 
55 
57  ObsCovT R,
58  const AlphaT& alpha,
59  StateT state0,
60  StateCovT P0);
61  UnscentedKalmanFilter() = delete;
62 
63 private:
64  PropCovT Q_;
65  PropCovT chol_Q_;
66  ObsCovT R_;
67  AlphaT alpha_;
68  StateT state_;
69  StateCovT P_;
70 
71  struct Weights
72  {
73  struct W
74  {
75  W(size_t l, FloatT alpha);
76  float sqrt_d_lambda, wj, wm, w0;
77  };
78 
79  explicit Weights(AlphaT alpha);
80  W state, control, update;
81  };
82 
83  Weights weights_;
84  StateCovT calculateClosestPosSemidefMatrix(const StateCovT& cov);
85 
86 public:
87  void propagation(const ControlT& omega, FloatT dt);
88  void update(const ObsT& y);
89  const StateT& getCurrentState() const;
90  const StateCovT& getCurrentStateCovariance() const;
91 };
92 
93 extern template class UnscentedKalmanFilter<SystemModelSE3<float>>;
97 
98 template <typename SystemModelT>
100 {
101 public:
102  using FloatT = typename SystemModelT::FloatT;
103  static constexpr float eps = 10 * std::numeric_limits<float>::epsilon();
104  // variable dimensions:
105  using dim = typename SystemModelT::dim;
106  using StateT = typename SystemModelT::StateT;
107  using SigmaPointsT = typename SystemModelT::SigmaPointsT; // todo: rename
108 
113 
114 
116  const AlphaT& alpha,
117  StateT state0,
118  StateCovT P0);
120 
121 private:
122  ObsCovT R_;
123  AlphaT alpha_;
124  StateT state_;
125  StateCovT P_;
126 
127  struct Weights
128  {
129  struct W
130  {
131  W(size_t l, FloatT alpha);
132  float sqrt_d_lambda, wj, wm, w0;
133  };
134 
135  explicit Weights(AlphaT alpha);
136  W state, update;
137  };
138 
139  Weights weights_;
140  StateCovT calculateClosestPosSemidefMatrix(const StateCovT& cov);
141 
142 public:
143  void propagation(FloatT dt);
144  void update(const ObsT& y);
145  const StateT& getCurrentState() const;
146  const StateCovT& getCurrentStateCovariance() const;
147 };
148 
153 
154 #endif //ROBDEKON_UNSCENTEDKALMANFILTER_H
UnscentedKalmanFilter::dim
typename SystemModelT::dim dim
Definition: UnscentedKalmanFilter.h:42
UnscentedKalmanFilter
Definition: UnscentedKalmanFilter.h:36
UnscentedKalmanFilter::UnscentedKalmanFilter
UnscentedKalmanFilter()=delete
UnscentedKalmanFilterWithoutControl::Weights::W::sqrt_d_lambda
float sqrt_d_lambda
Definition: UnscentedKalmanFilter.h:132
UnscentedKalmanFilterWithoutControl::getCurrentStateCovariance
const StateCovT & getCurrentStateCovariance() const
Definition: UnscentedKalmanFilter.cpp:361
UnscentedKalmanFilter::FloatT
typename SystemModelT::FloatT FloatT
Definition: UnscentedKalmanFilter.h:39
UnscentedKalmanFilterWithoutControl::propagation
void propagation(FloatT dt)
Definition: UnscentedKalmanFilter.cpp:236
UnscentedKalmanFilterWithoutControl::eps
static constexpr float eps
Definition: UnscentedKalmanFilter.h:103
UnscentedKalmanFilter::Weights::W::sqrt_d_lambda
float sqrt_d_lambda
Definition: UnscentedKalmanFilter.h:76
UnscentedKalmanFilterWithoutControl::dim
typename SystemModelT::dim dim
Definition: UnscentedKalmanFilter.h:105
SystemModelSE3::StateT
StateSE3< FloatT > StateT
Definition: SystemModel.h:88
UnscentedKalmanFilter::propagation
void propagation(const ControlT &omega, FloatT dt)
Definition: UnscentedKalmanFilter.cpp:53
UnscentedKalmanFilter::StateT
typename SystemModelT::StateT StateT
Definition: UnscentedKalmanFilter.h:43
SystemModelSE3::ControlT
ControlSE3< FloatT > ControlT
Definition: SystemModel.h:89
UnscentedKalmanFilter::Weights::W::wm
float wm
Definition: UnscentedKalmanFilter.h:76
UnscentedKalmanFilter::Weights::W::wj
float wj
Definition: UnscentedKalmanFilter.h:76
UnscentedKalmanFilterWithoutControl::FloatT
typename SystemModelT::FloatT FloatT
Definition: UnscentedKalmanFilter.h:102
UnscentedKalmanFilter::ControlNoiseT
typename SystemModelT::ControlNoiseT ControlNoiseT
Definition: UnscentedKalmanFilter.h:46
UnscentedKalmanFilter::Weights::W
Definition: UnscentedKalmanFilter.h:73
UnscentedKalmanFilterWithoutControl::getCurrentState
const StateT & getCurrentState() const
Definition: UnscentedKalmanFilter.cpp:354
UnscentedKalmanFilter::eps
static constexpr float eps
Definition: UnscentedKalmanFilter.h:40
UnscentedKalmanFilter::update
void update(const ObsT &y)
Definition: UnscentedKalmanFilter.cpp:121
UnscentedKalmanFilterWithoutControl::StateT
typename SystemModelT::StateT StateT
Definition: UnscentedKalmanFilter.h:106
UnscentedKalmanFilterWithoutControl::SigmaPointsT
typename SystemModelT::SigmaPointsT SigmaPointsT
Definition: UnscentedKalmanFilter.h:107
SystemModelSE3::FloatT
floatT FloatT
Definition: SystemModel.h:87
UnscentedKalmanFilterWithoutControl::Weights::W::W
W(size_t l, FloatT alpha)
Definition: UnscentedKalmanFilter.cpp:387
UnscentedKalmanFilter::getCurrentState
const StateT & getCurrentState() const
Definition: UnscentedKalmanFilter.cpp:170
UnscentedKalmanFilterWithoutControl
Definition: UnscentedKalmanFilter.h:99
SystemModelSE3::dim
Definition: SystemModel.h:82
UnscentedKalmanFilterWithoutControl::UnscentedKalmanFilterWithoutControl
UnscentedKalmanFilterWithoutControl()=delete
UnscentedKalmanFilterWithoutControl::Weights::W
Definition: UnscentedKalmanFilter.h:129
UnscentedKalmanFilter::getCurrentStateCovariance
const StateCovT & getCurrentStateCovariance() const
Definition: UnscentedKalmanFilter.cpp:177
UnscentedKalmanFilterWithoutControl::Weights::W::wm
float wm
Definition: UnscentedKalmanFilter.h:132
SystemModelSE3::SigmaPointsT
Eigen::Matrix< FloatT, dim::state, 1 > SigmaPointsT
Definition: SystemModel.h:93
UnscentedKalmanFilterWithoutControl::Weights::W::wj
float wj
Definition: UnscentedKalmanFilter.h:132
Eigen::Matrix< FloatT, dim::state, dim::state >
UnscentedKalmanFilter::Weights::W::w0
float w0
Definition: UnscentedKalmanFilter.h:76
UnscentedKalmanFilter::SigmaPointsT
typename SystemModelT::SigmaPointsT SigmaPointsT
Definition: UnscentedKalmanFilter.h:47
UnscentedKalmanFilterWithoutControl::update
void update(const ObsT &y)
Definition: UnscentedKalmanFilter.cpp:302
SystemModel.h
SystemModelSE3::ControlNoiseT
Eigen::Matrix< FloatT, dim::control, 1 > ControlNoiseT
Definition: SystemModel.h:92
UnscentedKalmanFilter::Weights::W::W
W(size_t l, FloatT alpha)
Definition: UnscentedKalmanFilter.cpp:203
control
This file is part of ArmarX.
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:45
UnscentedKalmanFilter::ControlT
typename SystemModelT::ControlT ControlT
Definition: UnscentedKalmanFilter.h:44
UnscentedKalmanFilterWithoutControl::Weights::W::w0
float w0
Definition: UnscentedKalmanFilter.h:132