8 #include "pinocchio/parsers/urdf/model.hxx"
10 #include <urdf_model/model.h>
11 #include <urdf_parser/urdf_parser.h>
14 #include <boost/foreach.hpp>
33 const ::urdf::Rotation &
q =
Y.origin.rotation;
36 const Inertia::Matrix3 &
R =
40 I <<
Y.ixx,
Y.ixy,
Y.ixz,
Y.ixy,
Y.iyy,
Y.iyz,
Y.ixz,
Y.iyz,
Y.izz;
71 typedef UrdfVisitorBase::Vector Vector;
76 const ::urdf::JointConstSharedPtr joint =
77 ::urdf::const_pointer_cast<::urdf::Joint>(link->parent_joint);
84 const std::string & link_name = link->name;
85 const std::string & parent_link_name = link->getParent()->name;
86 std::ostringstream joint_info;
91 const SE3 jointPlacement =
96 Vector max_effort(1), max_velocity(1), min_config(1), max_config(1);
97 Vector friction(Vector::Constant(1, 0.)), damping(Vector::Constant(1, 0.));
98 Vector3 axis(joint->axis.x, joint->axis.y, joint->axis.z);
100 const Scalar infty = std::numeric_limits<Scalar>::infinity();
104 case ::urdf::Joint::FLOATING:
105 joint_info <<
"joint FreeFlyer";
107 max_effort = Vector::Constant(6, infty);
108 max_velocity = Vector::Constant(6, infty);
109 min_config = Vector::Constant(7, -infty);
110 max_config = Vector::Constant(7, infty);
111 min_config.tail<4>().setConstant(-1.01);
112 max_config.tail<4>().setConstant(1.01);
114 friction = Vector::Constant(6, 0.);
115 damping = Vector::Constant(6, 0.);
117 model.addJointAndBody(
118 UrdfVisitorBase::FLOATING,
axis, parentFrameId, jointPlacement, joint->name,
Y,
119 link->name, max_effort, max_velocity, min_config, max_config, friction, damping);
122 case ::urdf::Joint::REVOLUTE:
123 joint_info <<
"joint REVOLUTE with axis";
126 assert(joint->limits);
129 max_effort << joint->limits->effort;
130 max_velocity << joint->limits->velocity;
131 min_config << joint->limits->lower;
132 max_config << joint->limits->upper;
137 friction << joint->dynamics->friction;
138 damping << joint->dynamics->damping;
141 model.addJointAndBody(
142 UrdfVisitorBase::REVOLUTE,
axis, parentFrameId, jointPlacement, joint->name,
Y,
143 link->name, max_effort, max_velocity, min_config, max_config, friction, damping);
146 case ::urdf::Joint::CONTINUOUS:
147 joint_info <<
"joint CONTINUOUS with axis";
149 min_config.resize(2);
150 max_config.resize(2);
151 min_config << -1.01, -1.01;
152 max_config << 1.01, 1.01;
156 max_effort << joint->limits->effort;
157 max_velocity << joint->limits->velocity;
162 max_velocity << infty;
167 friction << joint->dynamics->friction;
168 damping << joint->dynamics->damping;
171 model.addJointAndBody(
172 UrdfVisitorBase::CONTINUOUS,
axis, parentFrameId, jointPlacement, joint->name,
Y,
173 link->name, max_effort, max_velocity, min_config, max_config, friction, damping);
176 case ::urdf::Joint::PRISMATIC:
177 joint_info <<
"joint PRISMATIC with axis";
180 assert(joint->limits);
183 max_effort << joint->limits->effort;
184 max_velocity << joint->limits->velocity;
185 min_config << joint->limits->lower;
186 max_config << joint->limits->upper;
191 friction << joint->dynamics->friction;
192 damping << joint->dynamics->damping;
195 model.addJointAndBody(
196 UrdfVisitorBase::PRISMATIC,
axis, parentFrameId, jointPlacement, joint->name,
Y,
197 link->name, max_effort, max_velocity, min_config, max_config, friction, damping);
200 case ::urdf::Joint::PLANAR:
201 joint_info <<
"joint PLANAR with normal axis along Z";
203 max_effort = Vector::Constant(3, infty);
204 max_velocity = Vector::Constant(3, infty);
205 min_config = Vector::Constant(4, -infty);
206 max_config = Vector::Constant(4, infty);
207 min_config.tail<2>().setConstant(-1.01);
208 max_config.tail<2>().setConstant(1.01);
210 friction = Vector::Constant(3, 0.);
211 damping = Vector::Constant(3, 0.);
213 model.addJointAndBody(
214 UrdfVisitorBase::PLANAR,
axis, parentFrameId, jointPlacement, joint->name,
Y,
215 link->name, max_effort, max_velocity, min_config, max_config, friction, damping);
218 case ::urdf::Joint::FIXED:
227 joint_info <<
"fixed joint";
228 model.addFixedJointAndBody(parentFrameId, jointPlacement,
joint_name,
Y, link_name);
232 throw std::invalid_argument(
"The type of joint " +
joint_name +
" is not supported.");
236 model <<
"Adding Body" <<
'\n'
237 <<
'\"' << link_name <<
"\" connected to \"" << parent_link_name
238 <<
"\" through joint \"" <<
joint_name <<
"\"\n"
239 <<
"joint type: " << joint_info.str() <<
'\n'
240 <<
"joint placement:\n"
241 << jointPlacement <<
'\n'
242 <<
"body info: " <<
'\n'
243 <<
" mass: " <<
Y.mass() <<
'\n'
244 <<
" lever: " <<
Y.lever().transpose() <<
'\n'
245 <<
" inertia elements (Ixx,Iyx,Iyy,Izx,Izy,Izz): "
246 <<
Y.inertia().data().transpose() <<
'\n'
249 else if (link->getParent())
250 throw std::invalid_argument(link->name +
" - joint information missing.");
252 BOOST_FOREACH (::urdf::LinkConstSharedPtr child, link->child_links)
268 model.setName(urdfTree->getName());
270 ::urdf::LinkConstSharedPtr root_link = urdfTree->getRoot();
273 BOOST_FOREACH (::urdf::LinkConstSharedPtr child, root_link->child_links)
281 ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile(
filename);
285 throw std::invalid_argument(
288 "contain a valid URDF model.");
293 ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDF(xmlString);
297 throw std::invalid_argument(
"The XML stream does not contain a valid "