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
35template <typename SystemModelT>
37{
38public:
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;
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);
62
63private:
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);
77 };
78
79 explicit Weights(AlphaT alpha);
80 W state, control, update;
81 };
82
83 Weights weights_;
84 StateCovT calculateClosestPosSemidefMatrix(const StateCovT& cov);
85
86public:
87 void propagation(const ControlT& omega, FloatT dt);
88 void update(const ObsT& y);
89 const StateT& getCurrentState() const;
91};
92
97
98template <typename SystemModelT>
100{
101public:
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
121private:
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);
133 };
134
135 explicit Weights(AlphaT alpha);
136 W state, update;
137 };
138
139 Weights weights_;
140 StateCovT calculateClosestPosSemidefMatrix(const StateCovT& cov);
141
142public:
143 void propagation(FloatT dt);
144 void update(const ObsT& y);
145 const StateT& getCurrentState() const;
147};
148
153
154#endif //ROBDEKON_UNSCENTEDKALMANFILTER_H
constexpr T dt
typename SystemModelT::StateT StateT
const StateCovT & getCurrentStateCovariance() const
Eigen::Matrix< FloatT, dim::obs, dim::obs > ObsCovT
Eigen::Matrix< FloatT, 3, 1 > AlphaT
typename SystemModelT::FloatT FloatT
typename SystemModelT::SigmaPointsT SigmaPointsT
Eigen::Matrix< FloatT, dim::state, dim::state > StateCovT
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
UnscentedKalmanFilterWithoutControl(ObsCovT R, const AlphaT &alpha, StateT state0, StateCovT P0)
typename SystemModelT::StateT StateT
const StateT & getCurrentState() const
void propagation(const ControlT &omega, FloatT dt)
UnscentedKalmanFilter()=delete
UnscentedKalmanFilter(const PropCovT &Q, ObsCovT R, const AlphaT &alpha, StateT state0, StateCovT P0)
Eigen::Matrix< FloatT, dim::control, dim::control > PropCovT
typename SystemModelT::dim dim
const StateCovT & getCurrentStateCovariance() const
Eigen::Matrix< FloatT, dim::obs, dim::obs > ObsCovT
typename SystemModelT::ControlNoiseT ControlNoiseT
Eigen::Matrix< FloatT, 3, 1 > AlphaT
typename SystemModelT::FloatT FloatT
typename SystemModelT::SigmaPointsT SigmaPointsT
Eigen::Matrix< FloatT, dim::state, dim::state > StateCovT
static constexpr float eps
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
typename SystemModelT::ControlT ControlT
This file is part of ArmarX.
ControlSE3< FloatT > ControlT
Definition SystemModel.h:89
StateSE3< FloatT > StateT
Definition SystemModel.h:88
Eigen::Matrix< FloatT, dim::state, 1 > SigmaPointsT
Definition SystemModel.h:93
Eigen::Matrix< FloatT, dim::control, 1 > ControlNoiseT
Definition SystemModel.h:91