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 
32 template <typename floatT>
35 {
36  ObsT observation = state.pose.log().coeffs();
37  return observation;
38 }
39 
40 template <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 
52 template <typename floatT>
55 {
56  SigmaPointsT sigma;
57  sigma = state2.pose.lminus(state1.pose).coeffs();
58  return sigma;
59 }
60 
61 template <typename floatT>
63 SystemModelSE3<floatT>::retraction(const StateT& state, const SigmaPointsT& sigmaPoints)
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 
76 template <typename floatT>
79 {
80  ObsT observation = state.pose.log().coeffs();
81  return observation;
82 }
83 
84 template <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);
95 
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;
104 }
105 
106 template <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 
121 template <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 
137 template <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 
147 template <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 
160 template <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 
174 template <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 
187 template struct SystemModelSE3<float>;
188 template struct SystemModelSE3<double>;
189 
190 template struct SystemModelSE3xV<float>;
191 template struct SystemModelSE3xV<double>;
192 
193 template struct SystemModelSO3xR3<float>;
194 template struct SystemModelSO3xR3<double>;
SystemModelSE3xV::FloatT
floatT FloatT
Definition: SystemModel.h:147
StateSO3xR3::position
Eigen::Matrix< floatT, 3, 1 > position
Definition: SystemModel.h:61
StateSE3xV::pose
manif::SE3< floatT > pose
Definition: SystemModel.h:53
SystemModelSO3xR3::observationFunction
static ObsT observationFunction(const StateT &state)
Definition: SystemModel.cpp:139
SystemModelSO3xR3::propagationFunction
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
Definition: SystemModel.cpp:149
SystemModelSE3xV::retraction
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
Definition: SystemModel.cpp:108
SystemModelSE3xV
Definition: SystemModel.h:138
ControlSE3
Definition: SystemModel.h:45
SystemModelSO3xR3::inverseRetraction
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)
Definition: SystemModel.cpp:176
SystemModelSE3::retraction
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
Definition: SystemModel.cpp:63
SystemModelSE3::inverseRetraction
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)
Definition: SystemModel.cpp:54
StateSO3xR3
Definition: SystemModel.h:58
SystemModelSO3xR3
Definition: SystemModel.h:108
StateSE3
Definition: SystemModel.h:39
SystemModelSO3xR3::retraction
static StateT retraction(const StateT &state, const SigmaPointsT &sigmaPoints)
Definition: SystemModel.cpp:162
SystemModelSE3::observationFunction
static ObsT observationFunction(const StateT &state)
Definition: SystemModel.cpp:34
StateSE3xV
Definition: SystemModel.h:51
ControlSE3xV
Definition: SystemModel.h:72
SystemModelSE3::propagationFunction
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
Definition: SystemModel.cpp:42
StateSO3xR3::orientation
manif::SO3< floatT > orientation
Definition: SystemModel.h:60
ControlSO3xR3
Definition: SystemModel.h:65
SystemModelSE3::FloatT
floatT FloatT
Definition: SystemModel.h:87
SystemModelSE3xV::inverseRetraction
static SigmaPointsT inverseRetraction(const StateT &state1, const StateT &state2)
Definition: SystemModel.cpp:123
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
SystemModel.h
SystemModelSE3
Definition: SystemModel.h:78
SystemModelSE3xV::observationFunction
static ObsT observationFunction(const StateT &state)
Definition: SystemModel.cpp:78
StateSE3xV::velocity
manif::SE3< floatT >::Tangent velocity
Definition: SystemModel.h:54
control
This file is part of ArmarX.
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:45
SystemModelSO3xR3::FloatT
floatT FloatT
Definition: SystemModel.h:117
SystemModelSE3xV::propagationFunction
static StateT propagationFunction(const StateT &state, const ControlT &control, const ControlNoiseT &noise, FloatT dt)
Definition: SystemModel.cpp:86
StateSE3::pose
manif::SE3< floatT > pose
Definition: SystemModel.h:41