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