SystemModel.cpp
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 18.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#include "SystemModel.h"
29
30#include <manif/SO3.h>
31
32template <typename floatT>
35{
36 ObsT observation = state.pose.log().coeffs();
37 return observation;
38}
39
40template <typename floatT>
43 const ControlT& control,
44 const ControlNoiseT& noise,
45 FloatT dt)
46{
47 StateT new_state;
48 new_state.pose = state.pose.template rplus(control.velocity * dt);
49 return new_state;
50}
51
52template <typename floatT>
55{
56 SigmaPointsT sigma;
57 sigma = state2.pose.lminus(state1.pose).coeffs();
58 return sigma;
59}
60
61template <typename floatT>
64{
65 StateT new_state;
66 manif::SE3Tangent<FloatT> tan;
67 tan.coeffs() << sigmaPoints;
68 auto e = tan.exp();
69 new_state.pose = state.pose.lplus(tan);
70 return new_state;
71}
72
73/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
76template <typename floatT>
79{
80 ObsT observation = state.pose.log().coeffs();
81 return observation;
82}
83
84template <typename floatT>
89 FloatT dt)
90{
91 // transform acceleration into global frame
92 // TODO: figure out what to do here; probably something with adjoint
93 // Eigen::Matrix<FloatT, 3, 1> local_acc = control.acceleration.segment(0, 3) + noise.template block<3, 1>(3, 0);
94 // Eigen::Matrix<FloatT, 3, 1> acc = state.pose.asSO3().template act(local_acc);
96 StateT new_state;
97 // manif::SO3<FloatT> rotation = state.pose.asSO3().lplus(
98 // manif::SO3Tangent<FloatT>(control.acceleration.segment(3, 3) * dt + noise.segment(0, 3)));
99 // Eigen::Matrix<FloatT, 3, 1> position = state.pose.translation() + state.velocity * dt + 0.5 * control * dt * dt;
100 new_state.pose =
101 state.pose.template lplus(state.velocity * dt + 0.5 * control.acceleration * dt * dt);
102 new_state.velocity = state.velocity + control.acceleration * dt;
103 return new_state;
105
106template <typename floatT>
109 const SystemModelSE3xV::SigmaPointsT& sigmaPoints)
110{
111 StateT new_state;
112 manif::SE3Tangent<FloatT> tan;
113 tan.coeffs() << sigmaPoints.template segment<6>(0);
114 new_state.pose = state.pose.lplus(tan);
115 tan.coeffs() << sigmaPoints.template segment<6>(6);
116 // TODO: this is probably not correct, i.e. there needs to be some interaction between velocity and pose
117 new_state.velocity += tan;
118 return new_state;
119}
120
121template <typename floatT>
124 const SystemModelSE3xV::StateT& state2)
125{
126 SigmaPointsT sigma;
127 sigma.template segment<6>(0) = state2.pose.lminus(state1.pose).coeffs();
128 // TODO: this is probably not correct; probably one cannot subtract two tangent vectors at two different poses
129 // from each other
130 sigma.template segment<6>(6) = (state2.velocity - state1.velocity).coeffs();
131 return sigma;
132}
133
134////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136
137template <typename floatT>
140{
141 ObsT observation;
142 observation.template segment<3>(0) = state.position;
143 observation.template segment<3>(3) = state.orientation.log().coeffs();
144 return observation;
145}
146
147template <typename floatT>
152 FloatT dt)
153{
154 StateT new_state;
155 new_state.orientation = state.orientation.template rplus(control.angular_velocity * dt);
156 new_state.position = state.position + control.euclidean_velocity * dt;
157 return new_state;
158}
159
160template <typename floatT>
163 const SystemModelSO3xR3::SigmaPointsT& sigmaPoints)
164{
165 StateT new_state;
166 manif::SO3Tangent<FloatT> tan;
167 tan.coeffs() << sigmaPoints.template segment<3>(3);
168 new_state.orientation = state.orientation.lplus(tan);
169
170 new_state.position = state.position + sigmaPoints.template segment<3>(0);
171 return new_state;
172}
173
174template <typename floatT>
177 const SystemModelSO3xR3::StateT& state2)
178{
179 SigmaPointsT sigma;
180 // TODO: check if right order of substraction
181 sigma.template segment<3>(0) = state1.position - state2.position;
182 sigma.template segment<3>(3) = state2.orientation.lminus(state1.orientation).coeffs();
183 return sigma;
184}
185
186
187template struct SystemModelSE3<float>;
188template struct SystemModelSE3<double>;
189
190template struct SystemModelSE3xV<float>;
191template struct SystemModelSE3xV<double>;
192
193template struct SystemModelSO3xR3<float>;
194template struct SystemModelSO3xR3<double>;
constexpr T dt
This file is part of ArmarX.
manif::SE3< floatT > pose
Definition SystemModel.h:41
manif::SE3< floatT >::Tangent velocity
Definition SystemModel.h:54
manif::SE3< floatT > pose
Definition SystemModel.h:53
manif::SO3< floatT > orientation
Definition SystemModel.h:60
Eigen::Matrix< floatT, 3, 1 > position
Definition SystemModel.h:61
ControlSE3< FloatT > ControlT
Definition SystemModel.h:89
StateSE3< FloatT > StateT
Definition SystemModel.h:88
static ObsT observationFunction(const StateT &state)
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
Eigen::Matrix< FloatT, dim::state, 1 > SigmaPointsT
Definition SystemModel.h:93
Eigen::Matrix< FloatT, dim::control, 1 > ControlNoiseT
Definition SystemModel.h:91
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
Definition SystemModel.h:90
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)
ControlSE3xV< FloatT > ControlT
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)
static ObsT observationFunction(const StateT &state)
Eigen::Matrix< FloatT, dim::state, 1 > SigmaPointsT
Eigen::Matrix< FloatT, dim::control, 1 > ControlNoiseT
StateSE3xV< FloatT > StateT
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
static ObsT observationFunction(const StateT &state)
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
StateSO3xR3< FloatT > StateT
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
ControlSO3xR3< FloatT > ControlT
Eigen::Matrix< FloatT, dim::state, 1 > SigmaPointsT
Eigen::Matrix< FloatT, dim::control, 1 > ControlNoiseT
Eigen::Matrix< FloatT, dim::obs, 1 > ObsT
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)