visitor.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2019 CNRS INRIA
3 //
4 
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 
17 {
18 
19  typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType;
20 
21  template<typename JointModel>
22  static void algo(
25  const pinocchio::Model & model,
27  pinocchio::JointIndex jindex)
28  {
32  BOOST_CHECK(jindex == jmodel.id());
33  std::cout << "joint name: " << jmodel.shortname() << std::endl;
34  }
35 };
36 
38 {
39 
40  typedef bf::vector<const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex> ArgsType;
41 
42  template<typename JointModel>
43  static void algo(
45  const pinocchio::Model & model,
47  pinocchio::JointIndex jindex)
48  {
52  BOOST_CHECK(jindex == jmodel.id());
53  std::cout << "joint name: " << jmodel.shortname() << std::endl;
54  }
55 };
56 
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 
69 {
70 
71  template<typename JointModel>
72  static void algo(
75  {
77  BOOST_CHECK(!jmodel.shortname().empty());
78  std::cout << "joint name: " << jmodel.shortname() << std::endl;
79  }
80 };
81 
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(
93  const pinocchio::Model & model,
95  pinocchio::JointIndex jindex)
96  {
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 
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(
118  const pinocchio::Model & model,
120  pinocchio::JointIndex jindex)
121  {
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 
133 {
134  template<typename JointModel1, typename JointModel2>
135  static void algo(
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 
147 {
148  template<typename JointModel1, typename JointModel2>
149  static void algo(
154  {
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 {
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 {
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 {
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 {
227 
228  static JointModel run(const pinocchio::Model & /* model*/)
229  {
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 {
241 
242  static JointModel run(const pinocchio::Model & /* model*/)
243  {
247 
251 
252  return jmodel;
253  }
254 };
255 
256 template<typename JointModel_>
257 struct init<pinocchio::JointModelMimic<JointModel_>>
258 {
260 
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 
272 {
274  : model(model)
275  {
276  }
277 
278  template<typename JointModel>
280  {
282  model.addJoint(model.joints.size() - 1, jmodel, pinocchio::SE3::Random(), jmodel.classname());
283  }
284 
286 };
287 
288 BOOST_AUTO_TEST_CASE(test_run_over_all_joints_unary_visitor)
289 {
290  using namespace pinocchio;
291 
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  {
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  {
307  }
308 
309  for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i)
310  {
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 
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  {
333  model.joints[i], model.joints[i], data.joints[i], data.joints[i],
335  }
336 
337  for (Model::JointIndex i = 1; i < (Model::JointIndex)model.njoints; ++i)
338  {
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()
SimpleBinaryVisitor3::algo
static void algo(const pinocchio::JointModelBase< JointModel1 > &jmodel1, const pinocchio::JointModelBase< JointModel2 > &jmodel2)
Definition: visitor.cpp:135
SimpleUnaryVisitor2::ArgsType
bf::vector< const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex > ArgsType
Definition: visitor.cpp:40
init< pinocchio::JointModelPrismaticUnalignedTpl< Scalar, Options > >::JointModel
pinocchio::JointModelPrismaticUnalignedTpl< Scalar, Options > JointModel
Definition: visitor.cpp:212
SimpleBinaryVisitor2::algo
static void algo(const pinocchio::JointModelBase< JointModel1 > &jmodel1, const pinocchio::JointModelBase< JointModel2 > &jmodel2, const pinocchio::Model &model, pinocchio::Data &data, pinocchio::JointIndex jindex)
Definition: visitor.cpp:115
pinocchio::JointModelRevoluteUnboundedUnalignedTpl
Definition: multibody/joint/fwd.hpp:46
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_run_over_all_joints_unary_visitor)
Definition: visitor.cpp:288
pinocchio::DataTpl
Definition: context/generic.hpp:25
init< pinocchio::JointModelCompositeTpl< Scalar, Options, JointCollection > >::JointModel
pinocchio::JointModelCompositeTpl< Scalar, Options, JointCollection > JointModel
Definition: visitor.cpp:240
pinocchio::JointModelMimic
Definition: joint-mimic.hpp:307
SimpleBinaryVisitor1
Definition: visitor.cpp:82
init< pinocchio::JointModelMimic< JointModel_ > >::JointModel
pinocchio::JointModelMimic< JointModel_ > JointModel
Definition: visitor.cpp:259
pinocchio::JointModelBase
Definition: joint-model-base.hpp:75
init::run
static JointModel_ run(const pinocchio::Model &)
Definition: visitor.cpp:174
pinocchio::JointDataBase
Definition: joint-data-base.hpp:161
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
AppendJointToModel::AppendJointToModel
AppendJointToModel(pinocchio::Model &model)
Definition: visitor.cpp:273
model.hpp
pinocchio::fusion::JointBinaryVisitorBase< SimpleBinaryVisitor1 >::run
static void run(const JointModelBase< JointModelDerived1 > &jmodel1, const JointModelBase< JointModelDerived2 > &jmodel2, typename JointModelBase< JointModelDerived1 >::JointDataDerived &jdata1, typename JointModelBase< JointModelDerived2 >::JointDataDerived &jdata2, ArgsTmp args)
Definition: joint-binary-visitor.hpp:31
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::python::context::JointModelRZ
JointModelRevoluteTpl< Scalar, Options, 2 > JointModelRZ
Definition: bindings/python/context/generic.hpp:79
pinocchio::ModelTpl::joints
JointModelVector joints
Vector of joint models.
Definition: multibody/model.hpp:119
pinocchio::fusion::JointBinaryVisitorBase
Base structure for Binary visitation of two JointModels. This structure provides runners to call the ...
Definition: joint-binary-visitor.hpp:27
SimpleBinaryVisitor3
Definition: visitor.cpp:132
SimpleUnaryVisitor4::algo
static void algo(const pinocchio::JointModelBase< JointModel > &jmodel, pinocchio::JointDataBase< typename JointModel::JointDataDerived > &jdata)
Definition: visitor.cpp:72
pinocchio::JointDataBase::classname
static std::string classname()
Definition: joint-data-base.hpp:265
SimpleUnaryVisitor3::algo
static void algo(const pinocchio::JointModelBase< JointModel > &jmodel)
Definition: visitor.cpp:61
visitor.hpp
init< pinocchio::JointModelPrismaticUnalignedTpl< Scalar, Options > >::run
static JointModel run(const pinocchio::Model &)
Definition: visitor.cpp:214
SimpleBinaryVisitor2
Definition: visitor.cpp:109
pinocchio::JointModelCompositeTpl::addJoint
JointModelDerived & addJoint(const JointModelBase< JointModel > &jmodel, const SE3 &placement=SE3::Identity())
Add a joint to the vector of joints.
Definition: joint-composite.hpp:278
pinocchio::fusion::JointUnaryVisitorBase
Base structure for Unary visitation of a JointModel. This structure provides runners to call the righ...
Definition: joint-unary-visitor.hpp:25
pinocchio::ModelTpl::addJoint
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
SimpleBinaryVisitor1::algo
static void algo(const pinocchio::JointModelBase< JointModel1 > &jmodel1, const pinocchio::JointModelBase< JointModel2 > &jmodel2, pinocchio::JointDataBase< typename JointModel1::JointDataDerived > &jdata1, pinocchio::JointDataBase< typename JointModel2::JointDataDerived > &jdata2, const pinocchio::Model &model, pinocchio::Data &data, pinocchio::JointIndex jindex)
Definition: visitor.cpp:88
anymal-simulation.model
model
Definition: anymal-simulation.py:8
pinocchio::ModelTpl::JointIndex
pinocchio::JointIndex JointIndex
Definition: multibody/model.hpp:67
pinocchio::python::context::JointModel
JointModelTpl< Scalar, Options > JointModel
Definition: bindings/python/context/generic.hpp:69
pinocchio::fusion::JointUnaryVisitorBase< SimpleUnaryVisitor1 >::run
static void run(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel, JointDataTpl< Scalar, Options, JointCollectionTpl > &jdata, ArgsTmp args)
Definition: joint-unary-visitor.hpp:33
init< pinocchio::JointModelTpl< Scalar, Options, JointCollection > >::run
static JointModel run(const pinocchio::Model &)
Definition: visitor.cpp:228
init< pinocchio::JointModelCompositeTpl< Scalar, Options, JointCollection > >::run
static JointModel run(const pinocchio::Model &)
Definition: visitor.cpp:242
SimpleUnaryVisitor1
Definition: visitor.cpp:16
SimpleBinaryVisitor4
Definition: visitor.cpp:146
SimpleUnaryVisitor3
Definition: visitor.cpp:57
pinocchio::JointModelRevoluteUnboundedUnalignedTpl::Vector3
Eigen::Matrix< Scalar, 3, 1, Options > Vector3
Definition: joint-revolute-unbounded-unaligned.hpp:138
pinocchio::JointModelTpl
Definition: multibody/joint/fwd.hpp:155
data.hpp
pinocchio::JointModelBase::shortname
std::string shortname() const
Definition: joint-model-base.hpp:214
init< pinocchio::JointModelRevoluteUnboundedUnalignedTpl< Scalar, Options > >::run
static JointModel run(const pinocchio::Model &)
Definition: visitor.cpp:200
SimpleBinaryVisitor1::ArgsType
bf::vector< const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex > ArgsType
Definition: visitor.cpp:85
SimpleBinaryVisitor4::algo
static void algo(const pinocchio::JointModelBase< JointModel1 > &jmodel1, const pinocchio::JointModelBase< JointModel2 > &jmodel2, pinocchio::JointDataBase< typename JointModel1::JointDataDerived > &jdata1, pinocchio::JointDataBase< typename JointModel2::JointDataDerived > &jdata2)
Definition: visitor.cpp:149
init< pinocchio::JointModelRevoluteUnboundedUnalignedTpl< Scalar, Options > >::JointModel
pinocchio::JointModelRevoluteUnboundedUnalignedTpl< Scalar, Options > JointModel
Definition: visitor.cpp:198
pinocchio::JointModelPrismaticUnalignedTpl::Vector3
Eigen::Matrix< Scalar, 3, 1, _Options > Vector3
Definition: joint-prismatic-unaligned.hpp:596
init< pinocchio::JointModelTpl< Scalar, Options, JointCollection > >::JointModel
pinocchio::JointModelTpl< Scalar, Options, JointCollection > JointModel
Definition: visitor.cpp:226
SimpleUnaryVisitor1::algo
static void algo(const pinocchio::JointModelBase< JointModel > &jmodel, pinocchio::JointDataBase< typename JointModel::JointDataDerived > &jdata, const pinocchio::Model &model, pinocchio::Data &data, pinocchio::JointIndex jindex)
Definition: visitor.cpp:22
init< pinocchio::JointModelMimic< JointModel_ > >::run
static JointModel run(const pinocchio::Model &model)
Definition: visitor.cpp:261
pinocchio::context::Vector3
Eigen::Matrix< Scalar, 3, 1, Options > Vector3
Definition: context/generic.hpp:53
pinocchio::JointModelRevoluteTpl
Definition: multibody/joint/fwd.hpp:33
init< pinocchio::JointModelRevoluteUnalignedTpl< Scalar, Options > >::JointModel
pinocchio::JointModelRevoluteUnalignedTpl< Scalar, Options > JointModel
Definition: visitor.cpp:184
pinocchio::JointModelRevoluteUnalignedTpl
Definition: multibody/joint/fwd.hpp:38
pinocchio::JointModelPrismaticUnalignedTpl
Definition: multibody/joint/fwd.hpp:94
SimpleUnaryVisitor2
Definition: visitor.cpp:37
pinocchio::JointModelCompositeTpl
Definition: multibody/joint/fwd.hpp:141
AppendJointToModel::operator()
void operator()(const pinocchio::JointModelBase< JointModel > &) const
Definition: visitor.cpp:279
SimpleUnaryVisitor4
Definition: visitor.cpp:68
pinocchio::SE3Tpl::Random
static SE3Tpl Random()
Definition: spatial/se3-tpl.hpp:154
init::run
static JointModel_ run()
Definition: all-joints.cpp:25
pinocchio::python::context::JointModelRY
JointModelRevoluteTpl< Scalar, Options, 1 > JointModelRY
Definition: bindings/python/context/generic.hpp:76
AppendJointToModel::model
pinocchio::Model & model
Definition: visitor.cpp:285
pinocchio::JointModelRevoluteUnalignedTpl::Vector3
Eigen::Matrix< Scalar, 3, 1, _Options > Vector3
Definition: joint-revolute-unaligned.hpp:614
boost::fusion
Definition: fusion.hpp:27
pinocchio::JointIndex
Index JointIndex
Definition: multibody/fwd.hpp:26
append-urdf-model-with-another-model.joint_id
joint_id
Definition: append-urdf-model-with-another-model.py:34
pinocchio::ModelTpl
Definition: context/generic.hpp:20
SimpleUnaryVisitor1::ArgsType
bf::vector< const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex > ArgsType
Definition: visitor.cpp:19
init
Definition: all-joints.cpp:20
SimpleUnaryVisitor2::algo
static void algo(const pinocchio::JointModelBase< JointModel > &jmodel, const pinocchio::Model &model, pinocchio::Data &data, pinocchio::JointIndex jindex)
Definition: visitor.cpp:43
SimpleBinaryVisitor2::ArgsType
bf::vector< const pinocchio::Model &, pinocchio::Data &, pinocchio::JointIndex > ArgsType
Definition: visitor.cpp:112
pinocchio::JointCollectionDefaultTpl::JointModelVariant
boost::variant< JointModelRX, JointModelRY, JointModelRZ, JointModelMimicRX, JointModelMimicRY, JointModelMimicRZ, JointModelFreeFlyer, JointModelPlanar, JointModelRevoluteUnaligned, JointModelSpherical, JointModelSphericalZYX, JointModelPX, JointModelPY, JointModelPZ, JointModelPrismaticUnaligned, JointModelTranslation, JointModelRUBX, JointModelRUBY, JointModelRUBZ, JointModelRevoluteUnboundedUnaligned, JointModelHx, JointModelHy, JointModelHz, JointModelHelicalUnaligned, JointModelUniversal, boost::recursive_wrapper< JointModelComposite > > JointModelVariant
Definition: joint-collection.hpp:113
AppendJointToModel
Definition: visitor.cpp:271
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio::python::context::JointModelRX
JointModelRevoluteTpl< Scalar, Options, 0 > JointModelRX
Definition: bindings/python/context/generic.hpp:73
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
PINOCCHIO_UNUSED_VARIABLE
#define PINOCCHIO_UNUSED_VARIABLE(var)
Helper to declare that a parameter is unused.
Definition: include/pinocchio/macros.hpp:72
init< pinocchio::JointModelRevoluteUnalignedTpl< Scalar, Options > >::run
static JointModel run(const pinocchio::Model &)
Definition: visitor.cpp:186
pinocchio::JointModelBase::id
JointIndex id() const
Definition: joint-model-base.hpp:168


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:13