Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015-2019 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#include "pinocchio/multibody/model.hpp" |
6 |
|
|
#include "pinocchio/multibody/data.hpp" |
7 |
|
|
#include "pinocchio/multibody/visitor.hpp" |
8 |
|
|
|
9 |
|
|
#include <iostream> |
10 |
|
|
|
11 |
|
|
#include <boost/test/unit_test.hpp> |
12 |
|
|
#include <boost/utility/binary.hpp> |
13 |
|
|
|
14 |
|
|
namespace bf = boost::fusion; |
15 |
|
|
|
16 |
|
|
struct SimpleUnaryVisitor1 : public pinocchio::fusion::JointUnaryVisitorBase<SimpleUnaryVisitor1> |
17 |
|
|
{ |
18 |
|
|
|
19 |
|
|
typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType; |
20 |
|
|
|
21 |
|
|
template<typename JointModel> |
22 |
|
✗ |
static void algo( |
23 |
|
|
const pinocchio::JointModelBase<JointModel> & jmodel, |
24 |
|
|
pinocchio::JointDataBase<typename JointModel::JointDataDerived> & jdata, |
25 |
|
|
const pinocchio::Model & model, |
26 |
|
|
pinocchio::Data & data, |
27 |
|
|
pinocchio::JointIndex jindex) |
28 |
|
|
{ |
29 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata); |
30 |
|
|
PINOCCHIO_UNUSED_VARIABLE(model); |
31 |
|
|
PINOCCHIO_UNUSED_VARIABLE(data); |
32 |
|
✗ |
BOOST_CHECK(jindex == jmodel.id()); |
33 |
|
✗ |
std::cout << "joint name: " << jmodel.shortname() << std::endl; |
34 |
|
|
} |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
struct SimpleUnaryVisitor2 : public pinocchio::fusion::JointUnaryVisitorBase<SimpleUnaryVisitor2> |
38 |
|
|
{ |
39 |
|
|
|
40 |
|
|
typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType; |
41 |
|
|
|
42 |
|
|
template<typename JointModel> |
43 |
|
✗ |
static void algo( |
44 |
|
|
const pinocchio::JointModelBase<JointModel> & jmodel, |
45 |
|
|
const pinocchio::Model & model, |
46 |
|
|
pinocchio::Data & data, |
47 |
|
|
pinocchio::JointIndex jindex) |
48 |
|
|
{ |
49 |
|
|
PINOCCHIO_UNUSED_VARIABLE(model); |
50 |
|
|
PINOCCHIO_UNUSED_VARIABLE(data); |
51 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jindex); |
52 |
|
✗ |
BOOST_CHECK(jindex == jmodel.id()); |
53 |
|
✗ |
std::cout << "joint name: " << jmodel.shortname() << std::endl; |
54 |
|
|
} |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
struct SimpleUnaryVisitor3 : public pinocchio::fusion::JointUnaryVisitorBase<SimpleUnaryVisitor3> |
58 |
|
|
{ |
59 |
|
|
|
60 |
|
|
template<typename JointModel> |
61 |
|
✗ |
static void algo(const pinocchio::JointModelBase<JointModel> & jmodel) |
62 |
|
|
{ |
63 |
|
✗ |
BOOST_CHECK(!jmodel.shortname().empty()); |
64 |
|
✗ |
std::cout << "joint name: " << jmodel.shortname() << std::endl; |
65 |
|
|
} |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
struct SimpleUnaryVisitor4 : public pinocchio::fusion::JointUnaryVisitorBase<SimpleUnaryVisitor4> |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
|
template<typename JointModel> |
72 |
|
✗ |
static void algo( |
73 |
|
|
const pinocchio::JointModelBase<JointModel> & jmodel, |
74 |
|
|
pinocchio::JointDataBase<typename JointModel::JointDataDerived> & jdata) |
75 |
|
|
{ |
76 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata); |
77 |
|
✗ |
BOOST_CHECK(!jmodel.shortname().empty()); |
78 |
|
✗ |
std::cout << "joint name: " << jmodel.shortname() << std::endl; |
79 |
|
|
} |
80 |
|
|
}; |
81 |
|
|
|
82 |
|
|
struct SimpleBinaryVisitor1 : public pinocchio::fusion::JointBinaryVisitorBase<SimpleBinaryVisitor1> |
83 |
|
|
{ |
84 |
|
|
|
85 |
|
|
typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType; |
86 |
|
|
|
87 |
|
|
template<typename JointModel1, typename JointModel2> |
88 |
|
✗ |
static void algo( |
89 |
|
|
const pinocchio::JointModelBase<JointModel1> & jmodel1, |
90 |
|
|
const pinocchio::JointModelBase<JointModel2> & jmodel2, |
91 |
|
|
pinocchio::JointDataBase<typename JointModel1::JointDataDerived> & jdata1, |
92 |
|
|
pinocchio::JointDataBase<typename JointModel2::JointDataDerived> & jdata2, |
93 |
|
|
const pinocchio::Model & model, |
94 |
|
|
pinocchio::Data & data, |
95 |
|
|
pinocchio::JointIndex jindex) |
96 |
|
|
{ |
97 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata1); |
98 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata2); |
99 |
|
|
PINOCCHIO_UNUSED_VARIABLE(model); |
100 |
|
|
PINOCCHIO_UNUSED_VARIABLE(data); |
101 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jindex); |
102 |
|
✗ |
BOOST_CHECK(jindex == jmodel1.id()); |
103 |
|
✗ |
BOOST_CHECK(jindex == jmodel2.id()); |
104 |
|
✗ |
std::cout << "joint1 name: " << jmodel1.shortname() << std::endl; |
105 |
|
✗ |
std::cout << "joint2 name: " << jmodel2.shortname() << std::endl; |
106 |
|
|
} |
107 |
|
|
}; |
108 |
|
|
|
109 |
|
|
struct SimpleBinaryVisitor2 : public pinocchio::fusion::JointBinaryVisitorBase<SimpleBinaryVisitor2> |
110 |
|
|
{ |
111 |
|
|
|
112 |
|
|
typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType; |
113 |
|
|
|
114 |
|
|
template<typename JointModel1, typename JointModel2> |
115 |
|
✗ |
static void algo( |
116 |
|
|
const pinocchio::JointModelBase<JointModel1> & jmodel1, |
117 |
|
|
const pinocchio::JointModelBase<JointModel2> & jmodel2, |
118 |
|
|
const pinocchio::Model & model, |
119 |
|
|
pinocchio::Data & data, |
120 |
|
|
pinocchio::JointIndex jindex) |
121 |
|
|
{ |
122 |
|
|
PINOCCHIO_UNUSED_VARIABLE(model); |
123 |
|
|
PINOCCHIO_UNUSED_VARIABLE(data); |
124 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jindex); |
125 |
|
✗ |
BOOST_CHECK(jindex == jmodel1.id()); |
126 |
|
✗ |
BOOST_CHECK(jindex == jmodel2.id()); |
127 |
|
✗ |
std::cout << "joint1 name: " << jmodel1.shortname() << std::endl; |
128 |
|
✗ |
std::cout << "joint2 name: " << jmodel2.shortname() << std::endl; |
129 |
|
|
} |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
struct SimpleBinaryVisitor3 : public pinocchio::fusion::JointBinaryVisitorBase<SimpleBinaryVisitor3> |
133 |
|
|
{ |
134 |
|
|
template<typename JointModel1, typename JointModel2> |
135 |
|
✗ |
static void algo( |
136 |
|
|
const pinocchio::JointModelBase<JointModel1> & jmodel1, |
137 |
|
|
const pinocchio::JointModelBase<JointModel2> & jmodel2) |
138 |
|
|
{ |
139 |
|
✗ |
BOOST_CHECK(!jmodel1.shortname().empty()); |
140 |
|
✗ |
BOOST_CHECK(!jmodel2.shortname().empty()); |
141 |
|
✗ |
std::cout << "joint1 name: " << jmodel1.shortname() << std::endl; |
142 |
|
✗ |
std::cout << "joint2 name: " << jmodel2.shortname() << std::endl; |
143 |
|
|
} |
144 |
|
|
}; |
145 |
|
|
|
146 |
|
|
struct SimpleBinaryVisitor4 : public pinocchio::fusion::JointBinaryVisitorBase<SimpleBinaryVisitor4> |
147 |
|
|
{ |
148 |
|
|
template<typename JointModel1, typename JointModel2> |
149 |
|
✗ |
static void algo( |
150 |
|
|
const pinocchio::JointModelBase<JointModel1> & jmodel1, |
151 |
|
|
const pinocchio::JointModelBase<JointModel2> & jmodel2, |
152 |
|
|
pinocchio::JointDataBase<typename JointModel1::JointDataDerived> & jdata1, |
153 |
|
|
pinocchio::JointDataBase<typename JointModel2::JointDataDerived> & jdata2) |
154 |
|
|
{ |
155 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata1); |
156 |
|
|
PINOCCHIO_UNUSED_VARIABLE(jdata2); |
157 |
|
✗ |
BOOST_CHECK(!jmodel1.shortname().empty()); |
158 |
|
✗ |
BOOST_CHECK(!jmodel2.shortname().empty()); |
159 |
|
✗ |
std::cout << "joint1 name: " << jmodel1.shortname() << std::endl; |
160 |
|
✗ |
std::cout << "joint2 name: " << jmodel2.shortname() << std::endl; |
161 |
|
✗ |
std::cout << "jdata1 name: " << jdata1.classname() << std::endl; |
162 |
|
✗ |
std::cout << "jdata2 name: " << jdata2.classname() << std::endl; |
163 |
|
|
} |
164 |
|
|
}; |
165 |
|
|
|
166 |
|
|
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) |
167 |
|
|
|
168 |
|
|
template<typename JointModel_> |
169 |
|
|
struct init; |
170 |
|
|
|
171 |
|
|
template<typename JointModel_> |
172 |
|
|
struct init |
173 |
|
|
{ |
174 |
|
✗ |
static JointModel_ run(const pinocchio::Model & /* model*/) |
175 |
|
|
{ |
176 |
|
✗ |
JointModel_ jmodel; |
177 |
|
✗ |
return jmodel; |
178 |
|
|
} |
179 |
|
|
}; |
180 |
|
|
|
181 |
|
|
template<typename Scalar, int Options> |
182 |
|
|
struct init<pinocchio::JointModelRevoluteUnalignedTpl<Scalar, Options>> |
183 |
|
|
{ |
184 |
|
|
typedef pinocchio::JointModelRevoluteUnalignedTpl<Scalar, Options> JointModel; |
185 |
|
|
|
186 |
|
✗ |
static JointModel run(const pinocchio::Model & /* model*/) |
187 |
|
|
{ |
188 |
|
|
typedef typename JointModel::Vector3 Vector3; |
189 |
|
✗ |
JointModel jmodel(Vector3::Random().normalized()); |
190 |
|
|
|
191 |
|
✗ |
return jmodel; |
192 |
|
|
} |
193 |
|
|
}; |
194 |
|
|
|
195 |
|
|
template<typename Scalar, int Options> |
196 |
|
|
struct init<pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar, Options>> |
197 |
|
|
{ |
198 |
|
|
typedef pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar, Options> JointModel; |
199 |
|
|
|
200 |
|
✗ |
static JointModel run(const pinocchio::Model & /* model*/) |
201 |
|
|
{ |
202 |
|
|
typedef typename JointModel::Vector3 Vector3; |
203 |
|
✗ |
JointModel jmodel(Vector3::Random().normalized()); |
204 |
|
|
|
205 |
|
✗ |
return jmodel; |
206 |
|
|
} |
207 |
|
|
}; |
208 |
|
|
|
209 |
|
|
template<typename Scalar, int Options> |
210 |
|
|
struct init<pinocchio::JointModelPrismaticUnalignedTpl<Scalar, Options>> |
211 |
|
|
{ |
212 |
|
|
typedef pinocchio::JointModelPrismaticUnalignedTpl<Scalar, Options> JointModel; |
213 |
|
|
|
214 |
|
✗ |
static JointModel run(const pinocchio::Model & /* model*/) |
215 |
|
|
{ |
216 |
|
|
typedef typename JointModel::Vector3 Vector3; |
217 |
|
✗ |
JointModel jmodel(Vector3::Random().normalized()); |
218 |
|
|
|
219 |
|
✗ |
return jmodel; |
220 |
|
|
} |
221 |
|
|
}; |
222 |
|
|
|
223 |
|
|
template<typename Scalar, int Options, template<typename, int> class JointCollection> |
224 |
|
|
struct init<pinocchio::JointModelTpl<Scalar, Options, JointCollection>> |
225 |
|
|
{ |
226 |
|
|
typedef pinocchio::JointModelTpl<Scalar, Options, JointCollection> JointModel; |
227 |
|
|
|
228 |
|
|
static JointModel run(const pinocchio::Model & /* model*/) |
229 |
|
|
{ |
230 |
|
|
typedef pinocchio::JointModelRevoluteTpl<Scalar, Options, 0> JointModelRX; |
231 |
|
|
JointModel jmodel((JointModelRX())); |
232 |
|
|
|
233 |
|
|
return jmodel; |
234 |
|
|
} |
235 |
|
|
}; |
236 |
|
|
|
237 |
|
|
template<typename Scalar, int Options, template<typename, int> class JointCollection> |
238 |
|
|
struct init<pinocchio::JointModelCompositeTpl<Scalar, Options, JointCollection>> |
239 |
|
|
{ |
240 |
|
|
typedef pinocchio::JointModelCompositeTpl<Scalar, Options, JointCollection> JointModel; |
241 |
|
|
|
242 |
|
✗ |
static JointModel run(const pinocchio::Model & /* model*/) |
243 |
|
|
{ |
244 |
|
|
typedef pinocchio::JointModelRevoluteTpl<Scalar, Options, 0> JointModelRX; |
245 |
|
|
typedef pinocchio::JointModelRevoluteTpl<Scalar, Options, 1> JointModelRY; |
246 |
|
|
typedef pinocchio::JointModelRevoluteTpl<Scalar, Options, 2> JointModelRZ; |
247 |
|
|
|
248 |
|
✗ |
JointModel jmodel(JointModelRX(), pinocchio::SE3::Random()); |
249 |
|
✗ |
jmodel.addJoint(JointModelRY(), pinocchio::SE3::Random()); |
250 |
|
✗ |
jmodel.addJoint(JointModelRZ(), pinocchio::SE3::Random()); |
251 |
|
|
|
252 |
|
✗ |
return jmodel; |
253 |
|
|
} |
254 |
|
|
}; |
255 |
|
|
|
256 |
|
|
template<typename JointModel_> |
257 |
|
|
struct init<pinocchio::JointModelMimic<JointModel_>> |
258 |
|
|
{ |
259 |
|
|
typedef pinocchio::JointModelMimic<JointModel_> JointModel; |
260 |
|
|
|
261 |
|
✗ |
static JointModel run(const pinocchio::Model & model) |
262 |
|
|
{ |
263 |
|
✗ |
const pinocchio::JointIndex joint_id = model.getJointId(JointModel_::classname()); |
264 |
|
|
|
265 |
|
✗ |
JointModel jmodel(boost::get<JointModel_>(model.joints[joint_id]), 1., 0.); |
266 |
|
|
|
267 |
|
✗ |
return jmodel; |
268 |
|
|
} |
269 |
|
|
}; |
270 |
|
|
|
271 |
|
|
struct AppendJointToModel |
272 |
|
|
{ |
273 |
|
✗ |
AppendJointToModel(pinocchio::Model & model) |
274 |
|
✗ |
: model(model) |
275 |
|
|
{ |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
template<typename JointModel> |
279 |
|
✗ |
void operator()(const pinocchio::JointModelBase<JointModel> &) const |
280 |
|
|
{ |
281 |
|
✗ |
JointModel jmodel = init<JointModel>::run(model); |
282 |
|
✗ |
model.addJoint(model.joints.size() - 1, jmodel, pinocchio::SE3::Random(), jmodel.classname()); |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
pinocchio::Model & model; |
286 |
|
|
}; |
287 |
|
|
|
288 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_run_over_all_joints_unary_visitor) |
289 |
|
|
{ |
290 |
|
|
using namespace pinocchio; |
291 |
|
|
|
292 |
|
|
typedef JointCollectionDefault::JointModelVariant Variant; |
293 |
|
|
|
294 |
|
✗ |
Model model; |
295 |
|
✗ |
boost::mpl::for_each<Variant::types>(AppendJointToModel(model)); |
296 |
|
✗ |
Data data(model); |
297 |
|
|
|
298 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
299 |
|
|
{ |
300 |
|
✗ |
SimpleUnaryVisitor1::run( |
301 |
|
✗ |
model.joints[i], data.joints[i], SimpleUnaryVisitor1::ArgsType(model, data, i)); |
302 |
|
|
} |
303 |
|
|
|
304 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
305 |
|
|
{ |
306 |
|
✗ |
SimpleUnaryVisitor2::run(model.joints[i], SimpleUnaryVisitor2::ArgsType(model, data, i)); |
307 |
|
|
} |
308 |
|
|
|
309 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
310 |
|
|
{ |
311 |
|
✗ |
SimpleUnaryVisitor3::run(model.joints[i]); |
312 |
|
|
} |
313 |
|
|
|
314 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
315 |
|
|
{ |
316 |
|
✗ |
SimpleUnaryVisitor4::run(model.joints[i], data.joints[i]); |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
|
320 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_run_over_all_joints_binary_visitor) |
321 |
|
|
{ |
322 |
|
|
using namespace pinocchio; |
323 |
|
|
|
324 |
|
|
typedef JointCollectionDefault::JointModelVariant Variant; |
325 |
|
|
|
326 |
|
✗ |
Model model; |
327 |
|
✗ |
boost::mpl::for_each<Variant::types>(AppendJointToModel(model)); |
328 |
|
✗ |
Data data(model); |
329 |
|
|
|
330 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
331 |
|
|
{ |
332 |
|
✗ |
SimpleBinaryVisitor1::run( |
333 |
|
✗ |
model.joints[i], model.joints[i], data.joints[i], data.joints[i], |
334 |
|
✗ |
SimpleBinaryVisitor1::ArgsType(model, data, i)); |
335 |
|
|
} |
336 |
|
|
|
337 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
338 |
|
|
{ |
339 |
|
✗ |
SimpleBinaryVisitor2::run( |
340 |
|
✗ |
model.joints[i], model.joints[i], SimpleBinaryVisitor2::ArgsType(model, data, i)); |
341 |
|
|
} |
342 |
|
|
|
343 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
344 |
|
|
{ |
345 |
|
✗ |
SimpleBinaryVisitor3::run(model.joints[i], model.joints[i]); |
346 |
|
|
} |
347 |
|
|
|
348 |
|
✗ |
for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i) |
349 |
|
|
{ |
350 |
|
✗ |
SimpleBinaryVisitor4::run(model.joints[i], model.joints[i], data.joints[i], data.joints[i]); |
351 |
|
|
} |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
BOOST_AUTO_TEST_SUITE_END() |
355 |
|
|
|