Skip to content

Commit b67dc51

Browse files
authored
Merge pull request #447 from jcarpent/topic/urdf
Handle XML stream inside URDF parsers
2 parents 7b5fa8b + c0776ba commit b67dc51

File tree

5 files changed

+268
-48
lines changed

5 files changed

+268
-48
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ It is built upon Eigen for linear algebra and FCL for collision detections. **Pi
1515

1616
**Pinocchio** can be easily installed on various Linux and Unix distributions. Please refer to the [installation procedure](http://stack-of-tasks.github.io/pinocchio/download.html).
1717

18+
## Tutorials
19+
20+
**Pinocchio** is comming with a large bunch of tutorials aiming at introducting the basic tools for robotics control.
21+
The content of the tutorials are described [here](http://projects.laas.fr/gepetto/index.php/Teach/Supaero2018) and the code source of these tutorials is located [here](https://github.com/stack-of-tasks/pinocchio-tutorials).
22+
1823
## Dependencies
1924

2025
The Pinocchio software depends on several packages which
@@ -49,7 +54,7 @@ If you want to cite **Pinocchio** in your papers, please use the following bibte
4954
author = {Justin Carpentier and Florian Valenza and Nicolas Mansard and others},
5055
title = {Pinocchio: fast forward and inverse dynamics for poly-articulated systems},
5156
howpublished = {https://stack-of-tasks.github.io/pinocchio},
52-
year = {2015--2017}
57+
year = {2015--2018}
5358
}
5459
```
5560

bindings/python/parsers/parsers.hpp

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,23 @@ namespace se3
6969
se3::urdf::buildModel(filename, model);
7070
return model;
7171
}
72-
72+
73+
static Model buildModelFromXML(const std::string & XMLstream,
74+
bp::object & root_joint_object
75+
)
76+
{
77+
JointModelVariant root_joint = bp::extract<JointModelVariant> (root_joint_object)();
78+
Model model;
79+
se3::urdf::buildModelFromXML(XMLstream, root_joint, model);
80+
return model;
81+
}
82+
83+
static Model buildModelFromXML(const std::string & XMLstream)
84+
{
85+
Model model;
86+
se3::urdf::buildModelFromXML(XMLstream, model);
87+
return model;
88+
}
7389

7490
static GeometryModel
7591
buildGeomFromUrdf(const Model & model,
@@ -151,36 +167,49 @@ namespace se3
151167
bp::def("buildModelFromUrdf",
152168
static_cast <Model (*) (const std::string &, bp::object &)> (&ParsersPythonVisitor::buildModelFromUrdf),
153169
bp::args("Filename (string)","Root Joint Model"),
154-
"Parse the urdf file given in input and return a pinocchio model starting with the given root joint model"
155-
"(remember to create the corresponding data structure)."
170+
"Parse the URDF file given in input and return a pinocchio model starting with the given root joint model"
171+
"(remember to then create the corresponding Data structure associated to the model)."
156172
);
157173

158174
bp::def("buildModelFromUrdf",
159175
static_cast <Model (*) (const std::string &)> (&ParsersPythonVisitor::buildModelFromUrdf),
160176
bp::args("Filename (string)"),
161-
"Parse the urdf file given in input and return a pinocchio model"
162-
"(remember to create the corresponding data structure)."
177+
"Parse the URDF file given in input and return a pinocchio model"
178+
"(remember to then create the corresponding Data structure associated to the model)."
163179
);
164180

181+
bp::def("buildModelFromXML",
182+
static_cast <Model (*) (const std::string &, bp::object &)> (&ParsersPythonVisitor::buildModelFromXML),
183+
bp::args("XML stream (string)","Root Joint Model"),
184+
"Parse the URDF XML stream given in input and return a pinocchio model starting with the given root joint model"
185+
"(remember to then create the corresponding Data structure associated to the model)."
186+
);
187+
188+
bp::def("buildModelFromXML",
189+
static_cast <Model (*) (const std::string &)> (&ParsersPythonVisitor::buildModelFromXML),
190+
bp::args("XML stream (string)"),
191+
"Parse the URDF XML stream given in input and return a pinocchio model"
192+
"(remember to then create the corresponding Data structure associated to the model)."
193+
);
165194

166195
bp::def("buildGeomFromUrdf",
167196
static_cast <GeometryModel (*) (const Model &, const std::string &, const std::vector<std::string> &, const GeometryType)> (&ParsersPythonVisitor::buildGeomFromUrdf),
168197
bp::args("Model to assosiate the Geometry","filename (string)", "package_dirs (vector of strings)"
169198
),
170-
"Parse the urdf file given in input looking for the geometry of the given Model and return a proper pinocchio geometry model "
171-
"(remember to create the corresponding data structures).");
199+
"Parse the URDF file given in input looking for the geometry of the given Model and return a proper pinocchio geometry model "
200+
"(remember to then create the corresponding Data structure associated to the geometry model).");
172201

173202
bp::def("buildGeomFromUrdf",
174203
static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType)> (&ParsersPythonVisitor::buildGeomFromUrdf),
175204
bp::args("Model to assosiate the Geometry","filename (string)"),
176-
"Parse the urdf file given in input looking for the geometry of the given Model and return a proper pinocchio geometry model "
177-
"(remember to create the corresponding data structures).");
205+
"Parse the URDF file given in input looking for the geometry of the given Model and return a proper pinocchio geometry model "
206+
"(remember to then create the corresponding Data structure associated to the geometry model).");
178207

179208
#ifdef WITH_HPP_FCL
180209
bp::def("removeCollisionPairsFromSrdf",removeCollisionPairsFromSrdf,
181210
bp::args("Model", "GeometryModel (where pairs are removed)","srdf filename (string)", "verbosity"
182211
),
183-
"Parse an srdf file in order to desactivate collision pairs for a specific GeometryData and GeometryModel ");
212+
"Parse an SRDF file in order to desactivate collision pairs for a specific GeometryData and GeometryModel ");
184213

185214
#endif // #ifdef WITH_HPP_FCL
186215
#endif // #ifdef WITH_URDFDOM
@@ -190,7 +219,7 @@ namespace se3
190219
bp::args("Filename (string)",
191220
"Free flyer (bool, false for a fixed robot)",
192221
"Verbose option "),
193-
"Parse the urdf file given in input and return a proper pinocchio model "
222+
"Parse the URDF file given in input and return a proper pinocchio model "
194223
"(remember to create the corresponding data structure).");
195224
#endif // #ifdef WITH_LUA5
196225

@@ -202,7 +231,7 @@ namespace se3
202231

203232
bp::def("loadRotorParamsFromSrdf",loadRotorParamsFromSrdf,
204233
bp::args("Model for which we are loading the rotor parameters",
205-
"srdf filename (string)", "verbosity"),
234+
"SRDF filename (string)", "verbosity"),
206235
"Load the rotor parameters of a given model from an SRDF file.\n"
207236
"Results are stored in model.rotorInertia and model.rotorGearRatio.");
208237
}

src/parsers/urdf.hpp

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2015-2017 CNRS
2+
// Copyright (c) 2015-2018 CNRS
33
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
44
//
55
// This file is part of Pinocchio
@@ -87,6 +87,39 @@ namespace se3
8787
Model & buildModel (const ::urdf::ModelInterfaceSharedPtr & urdfTree,
8888
Model & model,
8989
const bool verbose = false);
90+
91+
///
92+
/// \brief Build the model from an XML stream with a particular joint as root of the model tree inside
93+
/// the model given as reference argument.
94+
///
95+
/// \param[in] xmlStream stream containing the URDF model.
96+
/// \param[in] rootJoint The joint at the root of the model tree.
97+
/// \param[in] verbose Print parsing info.
98+
/// \param[out] model Reference model where to put the parsed information.
99+
/// \return Return the reference on argument model for convenience.
100+
///
101+
/// \note urdfTree can be build from ::urdf::parseURDF
102+
/// or ::urdf::parseURDFFile
103+
Model & buildModelFromXML(const std::string & xmlStream,
104+
const JointModelVariant & rootJoint,
105+
Model & model,
106+
const bool verbose = false)
107+
throw (std::invalid_argument);
108+
109+
///
110+
/// \brief Build the model from an XML stream
111+
///
112+
/// \param[in] xmlStream stream containing the URDF model.
113+
/// \param[in] verbose Print parsing info.
114+
/// \param[out] model Reference model where to put the parsed information.
115+
/// \return Return the reference on argument model for convenience.
116+
///
117+
/// \note urdfTree can be build from ::urdf::parseURDF
118+
/// or ::urdf::parseURDFFile
119+
Model & buildModelFromXML(const std::string & xmlStream,
120+
Model & model,
121+
const bool verbose = false)
122+
throw (std::invalid_argument);
90123

91124

92125
/**
@@ -97,7 +130,7 @@ namespace se3
97130
* @param[in] model The model of the robot, built with
98131
* urdf::buildModel
99132
* @param[in] filename The URDF complete (absolute) file path
100-
* @param[in] packageDirs A vector containing the different directories
133+
* @param[in] packageDirs A vector containing the different directories
101134
* where to search for models and meshes, typically
102135
* obtained from calling se3::rosPaths()
103136
*
@@ -106,7 +139,7 @@ namespace se3
106139
*
107140
* @return Returns the reference on geom model for convenience.
108141
*
109-
* \warning If hpp-fcl has not been found during compilation, COLLISION types can not be loaded
142+
* \warning If hpp-fcl has not been found during compilation, COLLISION objects can not be loaded
110143
*
111144
*/
112145
GeometryModel& buildGeom(const Model & model,
@@ -115,6 +148,36 @@ namespace se3
115148
GeometryModel & geomModel,
116149
const std::vector<std::string> & packageDirs = std::vector<std::string> ())
117150
throw (std::invalid_argument);
151+
152+
/**
153+
* @brief Build The GeometryModel from a URDF file. Search for meshes
154+
* in the directories specified by the user first and then in
155+
* the environment variable ROS_PACKAGE_PATH
156+
*
157+
* @param[in] model The model of the robot, built with
158+
* urdf::buildModel
159+
* @param[in] filename The URDF complete (absolute) file path
160+
* @param[in] packageDir A string containing the path to the directories of the meshes,
161+
* typically obtained from calling se3::rosPaths().
162+
*
163+
* @param[in] type The type of objects that must be loaded (must be VISUAL or COLLISION)
164+
* @param[out] geomModel Reference where to put the parsed information.
165+
*
166+
* @return Returns the reference on geom model for convenience.
167+
*
168+
* \warning If hpp-fcl has not been found during compilation, COLLISION objects can not be loaded
169+
*
170+
*/
171+
inline GeometryModel& buildGeom(const Model & model,
172+
const std::string & filename,
173+
const GeometryType type,
174+
GeometryModel & geomModel,
175+
const std::string & packageDir)
176+
throw (std::invalid_argument)
177+
{
178+
const std::vector<std::string> dirs(1,packageDir);
179+
return buildGeom(model,filename,type,geomModel,dirs);
180+
}
118181

119182
/**
120183
* @brief Build The GeometryModel from a URDF model. Search for meshes
@@ -124,7 +187,7 @@ namespace se3
124187
* @param[in] model The model of the robot, built with
125188
* urdf::buildModel
126189
* @param[in] xmlStream Stream containing the URDF model
127-
* @param[in] packageDirs A vector containing the different directories
190+
* @param[in] packageDirs A vector containing the different directories
128191
* where to search for models and meshes, typically
129192
* obtained from calling se3::rosPaths()
130193
*
@@ -133,15 +196,45 @@ namespace se3
133196
*
134197
* @return Returns the reference on geom model for convenience.
135198
*
136-
* \warning If hpp-fcl has not been found during compilation, COLLISION types can not be loaded
199+
* \warning If hpp-fcl has not been found during compilation, COLLISION objects cannot be loaded
137200
*
138201
*/
139202
GeometryModel& buildGeom(const Model & model,
140-
const std::istream& xmlStream,
203+
const std::istream & xmlStream,
141204
const GeometryType type,
142205
GeometryModel & geomModel,
143206
const std::vector<std::string> & packageDirs = std::vector<std::string> ())
144207
throw (std::invalid_argument);
208+
209+
/**
210+
* @brief Build The GeometryModel from a URDF model. Search for meshes
211+
* in the directories specified by the user first and then in
212+
* the environment variable ROS_PACKAGE_PATH
213+
*
214+
* @param[in] model The model of the robot, built with
215+
* urdf::buildModel
216+
* @param[in] xmlStream Stream containing the URDF model
217+
* @param[in] packageDir A string containing the path to the directories of the meshes,
218+
* typically obtained from calling se3::rosPaths().
219+
*
220+
* @param[in] type The type of objects that must be loaded (must be VISUAL or COLLISION)
221+
* @param[out] geomModel Reference where to put the parsed information.
222+
*
223+
* @return Returns the reference on geom model for convenience.
224+
*
225+
* \warning If hpp-fcl has not been found during compilation, COLLISION objects cannot be loaded
226+
*
227+
*/
228+
inline GeometryModel & buildGeom(const Model & model,
229+
const std::istream & xmlStream,
230+
const GeometryType type,
231+
GeometryModel & geomModel,
232+
const std::string & packageDir)
233+
throw (std::invalid_argument)
234+
{
235+
const std::vector<std::string> dirs(1,packageDir);
236+
return buildGeom(model,xmlStream,type,geomModel,dirs);
237+
}
145238

146239

147240
} // namespace urdf

src/parsers/urdf/model.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2015-2017 CNRS
2+
// Copyright (c) 2015-2018 CNRS
33
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
44
//
55
// This file is part of Pinocchio
@@ -586,9 +586,9 @@ namespace se3
586586
::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile (filename);
587587

588588
if (urdfTree)
589-
{
589+
{
590590
return buildModel (urdfTree, root_joint, model, verbose);
591-
}
591+
}
592592
else
593593
{
594594
const std::string exception_message ("The file " + filename + " does not contain a valid URDF model.");
@@ -602,9 +602,9 @@ namespace se3
602602
{
603603
::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile (filename);
604604
if (urdfTree)
605-
{
605+
{
606606
return buildModel (urdfTree, model, verbose);
607-
}
607+
}
608608
else
609609
{
610610
const std::string exception_message ("The file " + filename + " does not contain a valid URDF model.");
@@ -613,6 +613,41 @@ namespace se3
613613

614614
return model;
615615
}
616+
617+
Model & buildModelFromXML(const std::string & xmlStream,
618+
const JointModelVariant & rootJoint,
619+
Model & model,
620+
const bool verbose) throw (std::invalid_argument)
621+
{
622+
::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDF(xmlStream);
623+
624+
if (urdfTree)
625+
return buildModel(urdfTree, rootJoint, model, verbose);
626+
else
627+
{
628+
const std::string exception_message ("The XML stream does not contain a valid URDF model.");
629+
throw std::invalid_argument(exception_message);
630+
}
631+
632+
return model;
633+
}
634+
635+
Model & buildModelFromXML(const std::string & xmlStream,
636+
Model & model,
637+
const bool verbose) throw (std::invalid_argument)
638+
{
639+
::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDF(xmlStream);
640+
641+
if (urdfTree)
642+
return buildModel(urdfTree, model, verbose);
643+
else
644+
{
645+
const std::string exception_message ("The XML stream does not contain a valid URDF model.");
646+
throw std::invalid_argument(exception_message);
647+
}
648+
649+
return model;
650+
}
616651

617652
Model& buildModel(const ::urdf::ModelInterfaceSharedPtr & urdfTree,
618653
const JointModelVariant & root_joint,

0 commit comments

Comments
 (0)