6 #include "pinocchio/parsers/urdf.hpp" 8 #include <urdf_model/model.h> 9 #include <urdf_parser/urdf_parser.h> 12 #include <boost/foreach.hpp> 30 const ::urdf::Vector3 & p = Y.origin.position;
31 const ::urdf::Rotation & q = Y.origin.rotation;
33 const Eigen::Vector3d com(p.x,p.y,p.z);
34 const Eigen::Matrix3d & R = Eigen::Quaterniond(q.w,q.x,q.y,q.z).matrix();
36 Eigen::Matrix3d I; I <<
40 return Inertia(Y.mass,com,R*I*R.transpose());
46 return Inertia::Zero();
58 const ::urdf::Vector3 & p = M.position;
59 const ::urdf::Rotation & q = M.rotation;
60 return SE3( Eigen::Quaterniond(q.w,q.x,q.y,q.z).matrix(), Eigen::Vector3d(p.x,p.y,p.z));
63 FrameIndex getParentLinkFrame(const ::urdf::LinkConstSharedPtr link,
64 UrdfVisitorBase& model)
66 PINOCCHIO_CHECK_INPUT_ARGUMENT(link && link->getParent());
67 FrameIndex
id = model.getBodyId(link->getParent()->name);
79 UrdfVisitorBase& model)
81 typedef UrdfVisitorBase::Scalar Scalar;
82 typedef UrdfVisitorBase::SE3
SE3;
83 typedef UrdfVisitorBase::Vector Vector;
84 typedef UrdfVisitorBase::Vector3 Vector3;
85 typedef Model::FrameIndex FrameIndex;
88 const ::urdf::JointConstSharedPtr joint =
89 ::urdf::const_pointer_cast< ::urdf::Joint>(link->parent_joint);
93 PINOCCHIO_CHECK_INPUT_ARGUMENT(link->getParent());
95 const std::string & joint_name = joint->name;
96 const std::string & link_name = link->name;
97 const std::string & parent_link_name = link->getParent()->name;
98 std::ostringstream joint_info;
100 FrameIndex parentFrameId = getParentLinkFrame(link, model);
103 const SE3 jointPlacement
108 Vector max_effort(1), max_velocity(1), min_config(1), max_config(1);
109 Vector3 axis (joint->axis.x, joint->axis.y, joint->axis.z);
111 const Scalar infty = std::numeric_limits<Scalar>::infinity();
115 case ::urdf::Joint::FLOATING:
116 joint_info <<
"joint FreeFlyer";
118 max_effort = Vector::Constant(6, infty);
119 max_velocity = Vector::Constant(6, infty);
120 min_config = Vector::Constant(7,-infty);
121 max_config = Vector::Constant(7, infty);
122 min_config.tail<4>().setConstant(-1.01);
123 max_config.tail<4>().setConstant( 1.01);
125 model.addJointAndBody(UrdfVisitorBase::FLOATING, axis,
126 parentFrameId,jointPlacement,joint->name,
128 max_effort,max_velocity,min_config,max_config);
131 case ::urdf::Joint::REVOLUTE:
132 joint_info <<
"joint REVOLUTE with axis";
135 assert(joint->limits);
138 max_effort << joint->limits->effort;
139 max_velocity << joint->limits->velocity;
140 min_config << joint->limits->lower;
141 max_config << joint->limits->upper;
144 model.addJointAndBody(UrdfVisitorBase::REVOLUTE, axis,
145 parentFrameId,jointPlacement,joint->name,
147 max_effort,max_velocity,min_config,max_config);
150 case ::urdf::Joint::CONTINUOUS:
151 joint_info <<
"joint CONTINUOUS with axis";
153 min_config.resize(2);
154 max_config.resize(2);
155 min_config << -1.01, -1.01;
156 max_config << 1.01, 1.01;
160 max_effort << joint->limits->effort;
161 max_velocity << joint->limits->velocity;
164 max_velocity << infty;
167 model.addJointAndBody(UrdfVisitorBase::CONTINUOUS, axis,
168 parentFrameId,jointPlacement,joint->name,
170 max_effort,max_velocity,min_config,max_config);
173 case ::urdf::Joint::PRISMATIC:
174 joint_info <<
"joint PRISMATIC with axis";
177 assert(joint->limits);
180 max_effort << joint->limits->effort;
181 max_velocity << joint->limits->velocity;
182 min_config << joint->limits->lower;
183 max_config << joint->limits->upper;
186 model.addJointAndBody(UrdfVisitorBase::PRISMATIC, axis,
187 parentFrameId,jointPlacement,joint->name,
189 max_effort,max_velocity,min_config,max_config);
192 case ::urdf::Joint::PLANAR:
193 joint_info <<
"joint PLANAR with normal axis along Z";
195 max_effort = Vector::Constant(3, infty);
196 max_velocity = Vector::Constant(3, infty);
197 min_config = Vector::Constant(4,-infty);
198 max_config = Vector::Constant(4, infty);
199 min_config.tail<2>().setConstant(-1.01);
200 max_config.tail<2>().setConstant( 1.01);
202 model.addJointAndBody(UrdfVisitorBase::PLANAR, axis,
203 parentFrameId,jointPlacement,joint->name,
205 max_effort,max_velocity,min_config,max_config);
208 case ::urdf::Joint::FIXED:
217 joint_info <<
"fixed joint";
218 model.addFixedJointAndBody(parentFrameId, jointPlacement,
219 joint_name, Y, link_name);
223 throw std::invalid_argument(
"The type of joint " + joint_name +
" is not supported.");
228 <<
"Adding Body" <<
'\n' 229 <<
'\"' << link_name <<
"\" connected to \"" << parent_link_name <<
"\" through joint \"" << joint_name <<
"\"\n" 230 <<
"joint type: " << joint_info.str() <<
'\n' 231 <<
"joint placement:\n" << jointPlacement <<
'\n' 232 <<
"body info: " <<
'\n' 233 <<
" mass: " << Y.mass() <<
'\n' 234 <<
" lever: " << Y.lever().transpose() <<
'\n' 235 <<
" inertia elements (Ixx,Iyx,Iyy,Izx,Izy,Izz): " << Y.inertia().data().transpose() <<
'\n' <<
'\n';
237 else if (link->getParent())
238 throw std::invalid_argument(link->name +
" - joint information missing.");
240 BOOST_FOREACH(::urdf::LinkConstSharedPtr child, link->child_links)
254 UrdfVisitorBase& model)
256 model.setName(urdfTree->getName());
258 ::urdf::LinkConstSharedPtr root_link = urdfTree->getRoot();
259 model.addRootJoint(
convertFromUrdf(root_link->inertial), root_link->name);
261 BOOST_FOREACH(::urdf::LinkConstSharedPtr child, root_link->child_links)
268 UrdfVisitorBase& model)
270 ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDFFile (filename);
274 throw std::invalid_argument(
"The file " + filename +
" does not " 275 "contain a valid URDF model.");
278 void parseRootTreeFromXML(
const std::string & xmlString,
279 UrdfVisitorBase& model)
281 ::urdf::ModelInterfaceSharedPtr urdfTree = ::urdf::parseURDF(xmlString);
285 throw std::invalid_argument(
"The XML stream does not contain a valid "
SE3 convertFromUrdf(const ::urdf::Pose &M)
Convert URDF Pose quantity to SE3.
JointIndex id(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdVisitor to get the index of the joint in the kinematic chain...
void parseTree(::urdf::LinkConstSharedPtr link, UrdfVisitorBase &model)
Recursive procedure for reading the URDF tree. The function returns an exception as soon as a necessa...
void parseRootTree(const ::urdf::ModelInterface *urdfTree, UrdfVisitorBase &model)
Parse a tree with a specific root joint linking the model to the environment. The function returns an...
Main pinocchio namespace.