urdf.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2022 CNRS INRIA
3 //
4 
5 #include <iostream>
6 #include <fstream>
7 #include <streambuf>
8 
11 
12 #ifdef PINOCCHIO_WITH_HPP_FCL
14 #endif // PINOCCHIO_WITH_HPP_FCL
15 
16 #include <boost/test/unit_test.hpp>
17 
18 #include <urdf_parser/urdf_parser.h>
19 
20 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
21 
23 {
24  const std::string filename =
26  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
27  const std::string dir = PINOCCHIO_MODEL_DIR;
28 
31  pinocchio::GeometryModel geomModel;
33 
34  BOOST_CHECK(model.nq == 31);
35 }
36 
37 BOOST_AUTO_TEST_CASE(build_model_with_root_joint_name)
38 {
39  const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
40  const std::string dir = PINOCCHIO_MODEL_DIR;
41 
44  BOOST_CHECK(model.names[1] == "root_joint");
45 
46  pinocchio::Model model_name;
47  const std::string name_ = "freeFlyer_joint";
49  BOOST_CHECK(model_name.names[1] == name_);
50 }
51 
52 BOOST_AUTO_TEST_CASE(build_model_simple_humanoid)
53 {
54  const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
55  const std::string dir = PINOCCHIO_MODEL_DIR;
56 
59 
60  BOOST_CHECK_EQUAL(model.nq, 29);
61 
62  // Check that parsing collision_checking works.
63  pinocchio::GeometryModel geomModel;
65  BOOST_CHECK_EQUAL(geomModel.ngeoms, 2);
66 
67 #ifdef PINOCCHIO_WITH_HPP_FCL
68  // Check that cylinder is converted into capsule.
69  #ifdef PINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME
70  BOOST_CHECK_EQUAL(geomModel.geometryObjects[0].geometry->getNodeType(), hpp::fcl::GEOM_CYLINDER);
71  #else // PINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME
72  BOOST_CHECK_EQUAL(geomModel.geometryObjects[0].geometry->getNodeType(), hpp::fcl::GEOM_CAPSULE);
73  #endif
74 
75  #ifndef PINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME
76  BOOST_CHECK_EQUAL(geomModel.geometryObjects[1].geometry->getNodeType(), hpp::fcl::GEOM_CONVEX);
77  #else // PINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME
78  BOOST_CHECK_EQUAL(geomModel.geometryObjects[1].geometry->getObjectType(), hpp::fcl::OT_BVH);
79  #endif
80 #endif // PINOCCHIO_WITH_HPP_FCL
81 
82  pinocchio::Model model_ff;
84 
85  BOOST_CHECK(model_ff.nq == 36);
86 }
87 
88 BOOST_AUTO_TEST_CASE(check_mesh_relative_path)
89 {
90  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
91  const std::string dir = PINOCCHIO_MODEL_DIR;
92 
93  pinocchio::Model model0;
95  pinocchio::GeometryModel geomModel0;
96  pinocchio::urdf::buildGeom(model0, filename, pinocchio::COLLISION, geomModel0, dir);
97  BOOST_CHECK_EQUAL(geomModel0.ngeoms, 2);
98 
99  // check if urdf with relative mesh path without //package can be loaded
100  filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid_rel_mesh.urdf");
103  pinocchio::GeometryModel geomModel1;
105  BOOST_CHECK_EQUAL(geomModel1.ngeoms, 2);
106 
107  BOOST_CHECK_EQUAL(
108  geomModel0.geometryObjects[1].name.compare(geomModel1.geometryObjects[1].name), 0);
109 }
110 
111 BOOST_AUTO_TEST_CASE(build_model_from_XML)
112 {
113  const std::string filename =
115  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
116 
117  // Read file as XML
118  std::ifstream file;
119  file.open(filename.c_str());
120  std::string filestr((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
121 
124 
125  BOOST_CHECK(model.nq == 31);
126 }
127 
128 BOOST_AUTO_TEST_CASE(check_tree_from_XML)
129 {
130  // Read file as XML
131  std::string filestr("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
132  "<robot name=\"test\">"
133  " <link name=\"base_link\"/>"
134  " <link name=\"link_1\"/>"
135  " <link name=\"link_2\"/>"
136  " <joint name=\"joint_1\" type=\"fixed\">"
137  " <origin xyz=\"1 0 0\"/>"
138  " <axis xyz=\"0 0 1\"/>"
139  " <parent link=\"base_link\"/>"
140  " <child link=\"link_1\"/>"
141  " </joint>"
142  " <joint name=\"joint_2\" type=\"fixed\">"
143  " <origin xyz=\"0 1 0\"/>"
144  " <axis xyz=\"0 0 1\"/>"
145  " <parent link=\"link_1\"/>"
146  " <child link=\"link_2\"/>"
147  " </joint>"
148  "</robot>");
149 
152 
153  pinocchio::JointIndex base_link_id = model.getFrameId("base_link"),
154  link1_id = model.getFrameId("link_1"),
155  link2_id = model.getFrameId("link_2"),
156  joint1_id = model.getFrameId("joint_1"),
157  joint2_id = model.getFrameId("joint_2");
158 
159  BOOST_CHECK_EQUAL(base_link_id, model.frames[joint1_id].parentFrame);
160  BOOST_CHECK_EQUAL(joint1_id, model.frames[link1_id].parentFrame);
161  BOOST_CHECK_EQUAL(link1_id, model.frames[joint2_id].parentFrame);
162  BOOST_CHECK_EQUAL(joint2_id, model.frames[link2_id].parentFrame);
163 }
164 
165 BOOST_AUTO_TEST_CASE(build_model_from_UDRFTree)
166 {
167  const std::string filename =
169  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
170 
171  ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile(filename);
172 
175 
176  BOOST_CHECK(model.nq == 31);
177 }
178 
179 BOOST_AUTO_TEST_CASE(build_model_with_joint)
180 {
181  const std::string filename =
183  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
184  const std::string dir = PINOCCHIO_MODEL_DIR;
185 
188  pinocchio::GeometryModel geomModel_collision, geomModel_visual;
189  pinocchio::urdf::buildGeom(model, filename, pinocchio::COLLISION, geomModel_collision, dir);
191 
192  BOOST_CHECK(model.nq == 38);
193 }
194 
195 BOOST_AUTO_TEST_CASE(build_model_with_joint_from_XML)
196 {
197  const std::string filename =
199  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
200 
201  // Read file as XML
202  std::ifstream file;
203  file.open(filename.c_str());
204  std::string filestr((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
205 
208 
209  BOOST_CHECK(model.nq == 38);
210 }
211 
212 BOOST_AUTO_TEST_CASE(build_model_with_joint_from_UDRFTree)
213 {
214  const std::string filename =
216  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
217 
218  ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile(filename);
219 
222 
223  BOOST_CHECK(model.nq == 38);
224 }
225 
226 BOOST_AUTO_TEST_CASE(append_two_URDF_models)
227 {
228  const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
229 
232 
233  BOOST_CHECK(model.njoints == 30);
234  const int nframes = model.nframes;
235  const std::string filestr("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
236  "<robot name=\"test\">"
237  " <link name=\"box\"/>"
238  "</robot>");
239 
241  BOOST_CHECK(model.njoints == 30);
242  BOOST_CHECK(nframes + 1 == model.nframes);
243 }
244 
245 BOOST_AUTO_TEST_CASE(append_two_URDF_models_with_root_joint)
246 {
247  const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
248 
251 
252  BOOST_CHECK(model.njoints == 31);
253  const std::string filestr("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
254  "<robot name=\"test\">"
255  " <link name=\"box\"/>"
256  "</robot>");
257 
258  BOOST_CHECK_THROW(
260  std::invalid_argument);
261 }
262 
263 BOOST_AUTO_TEST_CASE(check_specific_models)
264 {
265  const std::string filename = PINOCCHIO_MODEL_DIR + std::string("/baxter_simple.urdf");
266 
269 }
270 
271 #if defined(PINOCCHIO_WITH_HPP_FCL)
272 BOOST_AUTO_TEST_CASE(test_geometry_parsing)
273 {
274  typedef pinocchio::Model Model;
275  typedef pinocchio::GeometryModel GeometryModel;
276 
277  std::string filename =
279  + std::string("/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
280  std::vector<std::string> packageDirs;
281  std::string meshDir = PINOCCHIO_MODEL_DIR;
282  packageDirs.push_back(meshDir);
283 
284  Model model;
286  GeometryModel geomModel;
287  pinocchio::urdf::buildGeom(model, filename, pinocchio::COLLISION, geomModel, packageDirs);
288  geomModel.addAllCollisionPairs();
289 
290  GeometryModel geomModelOther =
291  pinocchio::urdf::buildGeom(model, filename, pinocchio::COLLISION, geomModel, packageDirs);
292  BOOST_CHECK(geomModelOther == geomModel);
293 }
294 #endif // if defined(PINOCCHIO_WITH_HPP_FCL)
295 
296 BOOST_AUTO_TEST_CASE(test_getFrameId_identical_link_and_joint_name)
297 {
298  // This test checks whether the input argument of getFrameId raises an exception when multiple
299  // frames with identical names are found. Note, a model that contains a link and a joint with the
300  // same name is valid, but the look-up for e.g. getFrameId requires the explicit specification of
301  // the FrameType in order to be valid. It resolved
302  // https://github.com/stack-of-tasks/pinocchio/issues/1771
304  const std::string filename =
305  PINOCCHIO_MODEL_DIR + std::string("/../unittest/models/link_and_joint_identical_name.urdf");
307 
308  BOOST_CHECK_THROW(model.getFrameId("base"), std::invalid_argument);
309  BOOST_CHECK(model.getFrameId("base", pinocchio::FrameType::BODY) == 1);
310  BOOST_CHECK(model.getFrameId("base", pinocchio::FrameType::FIXED_JOINT) == 2);
311 }
312 
313 BOOST_AUTO_TEST_SUITE_END()
pinocchio::ModelTpl::names
std::vector< std::string > names
Name of the joints.
Definition: multibody/model.hpp:142
model.hpp
hpp::fcl::GEOM_CONVEX
GEOM_CONVEX
pinocchio::JointModelFreeFlyerTpl
Definition: multibody/joint/fwd.hpp:110
pinocchio::python::context::Model
ModelTpl< Scalar, Options > Model
Definition: bindings/python/context/generic.hpp:63
pinocchio::urdf::buildModelFromXML
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModelFromXML(const std::string &xml_stream, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from an XML stream with a particular joint as root of the model tree inside the model...
hpp::fcl::OT_BVH
OT_BVH
pinocchio::VISUAL
@ VISUAL
Definition: multibody/geometry-object.hpp:26
anymal-simulation.model
model
Definition: anymal-simulation.py:8
pinocchio::GeometryModel::geometryObjects
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
Definition: multibody/geometry.hpp:217
filename
filename
urdf.hpp
pinocchio::urdf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
pinocchio::urdf::buildGeom
GeometryModel & buildGeom(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const GeometryType type, GeometryModel &geom_model, const std::vector< std::string > &package_paths=std::vector< std::string >(), ::hpp::fcl::MeshLoaderPtr mesh_loader=::hpp::fcl::MeshLoaderPtr())
Build The GeometryModel from a URDF file. Search for meshes in the directories specified by the user ...
pinocchio::GeometryModel::ngeoms
Index ngeoms
The number of GeometryObjects.
Definition: multibody/geometry.hpp:214
simulation-closed-kinematic-chains.joint1_id
joint1_id
Definition: simulation-closed-kinematic-chains.py:56
simulation-closed-kinematic-chains.joint2_id
joint2_id
Definition: simulation-closed-kinematic-chains.py:66
append-urdf-model-with-another-model.model1
model1
Definition: append-urdf-model-with-another-model.py:19
hpp::fcl::GEOM_CYLINDER
GEOM_CYLINDER
pinocchio::FIXED_JOINT
@ FIXED_JOINT
fixed joint frame: joint frame but for a fixed joint
Definition: multibody/frame.hpp:35
pinocchio::JointIndex
Index JointIndex
Definition: multibody/fwd.hpp:26
pinocchio::GeometryModel
Definition: multibody/geometry.hpp:50
pinocchio::COLLISION
@ COLLISION
Definition: multibody/geometry-object.hpp:27
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(build_model)
Definition: urdf.cpp:22
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::BODY
@ BODY
body frame: attached to the collision, inertial or visual properties of a link
Definition: multibody/frame.hpp:36
collision_object.h
hpp::fcl::GEOM_CAPSULE
GEOM_CAPSULE
pinocchio::ModelTpl::nq
int nq
Dimension of the configuration vector representation.
Definition: multibody/model.hpp:98
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:33