38 #include <boost/algorithm/string_regex.hpp> 39 #include <boost/math/constants/constants.hpp> 40 #include <geometry_msgs/Pose.h> 42 #include <urdf_parser/urdf_parser.h> 50 const std::string
LOGNAME =
"robot_model_builder";
62 std::string urdf_path;
63 if (robot_name ==
"pr2")
70 ros::package::getPath(
"moveit_resources_" + robot_name +
"_description") +
"/urdf/" + robot_name +
".urdf";
72 urdf::ModelInterfaceSharedPtr urdf_model = urdf::parseURDFFile(urdf_path);
73 if (urdf_model ==
nullptr)
75 ROS_ERROR_NAMED(LOGNAME,
"Cannot find URDF for %s. Make sure moveit_resources/your robot description is installed",
85 std::string srdf_path;
86 if (robot_name ==
"pr2")
93 ros::package::getPath(
"moveit_resources_" + robot_name +
"_moveit_config") +
"/config/" + robot_name +
".srdf";
95 srdf_model->initFile(*urdf_model, srdf_path);
100 : urdf_model_(new
urdf::ModelInterface()), srdf_writer_(new
srdf::SRDFWriter())
105 urdf::LinkSharedPtr base_link(
new urdf::Link);
106 base_link->name = base_link_name;
107 urdf_model_->links_.insert(std::make_pair(base_link_name, base_link));
113 const std::vector<geometry_msgs::Pose>& joint_origins, urdf::Vector3 joint_axis)
115 std::vector<std::string> link_names;
116 boost::split_regex(link_names, section, boost::regex(
"->"));
117 if (link_names.empty())
126 ROS_ERROR_NAMED(LOGNAME,
"Link %s not present in builder yet!", link_names[0].c_str());
131 if (!joint_origins.empty() && link_names.size() - 1 != joint_origins.size())
133 ROS_ERROR_NAMED(LOGNAME,
"There should be one more link (%zu) than there are joint origins (%zu)",
134 link_names.size(), joint_origins.size());
140 for (
size_t i = 1; i < link_names.size(); ++i)
145 ROS_ERROR_NAMED(LOGNAME,
"Link %s is already specified", link_names[i].c_str());
149 urdf::LinkSharedPtr link(
new urdf::Link);
150 link->name = link_names[i];
151 urdf_model_->links_.insert(std::make_pair(link_names[i], link));
152 urdf::JointSharedPtr joint(
new urdf::Joint);
153 joint->name = link_names[i - 1] +
"-" + link_names[i] +
"-joint";
155 joint->parent_to_joint_origin_transform.clear();
156 if (!joint_origins.empty())
158 geometry_msgs::Pose o = joint_origins[i - 1];
159 joint->parent_to_joint_origin_transform.position = urdf::Vector3(o.position.x, o.position.y, o.position.z);
160 joint->parent_to_joint_origin_transform.rotation =
161 urdf::Rotation(o.orientation.x, o.orientation.y, o.orientation.z, o.orientation.w);
164 joint->parent_link_name = link_names[i - 1];
165 joint->child_link_name = link_names[i];
166 if (type ==
"planar")
167 joint->type = urdf::Joint::PLANAR;
168 else if (type ==
"floating")
169 joint->type = urdf::Joint::FLOATING;
170 else if (type ==
"revolute")
171 joint->type = urdf::Joint::REVOLUTE;
172 else if (type ==
"continuous")
173 joint->type = urdf::Joint::CONTINUOUS;
174 else if (type ==
"prismatic")
175 joint->type = urdf::Joint::PRISMATIC;
176 else if (type ==
"fixed")
177 joint->type = urdf::Joint::FIXED;
185 joint->axis = joint_axis;
186 if (joint->type == urdf::Joint::REVOLUTE || joint->type == urdf::Joint::PRISMATIC)
188 urdf::JointLimitsSharedPtr limits(
new urdf::JointLimits);
189 limits->lower = -boost::math::constants::pi<double>();
190 limits->upper = boost::math::constants::pi<double>();
192 joint->limits = limits;
194 urdf_model_->joints_.insert(std::make_pair(joint->name, joint));
199 double ixy,
double ixz,
double iyy,
double iyz,
double izz)
203 ROS_ERROR_NAMED(LOGNAME,
"Link %s not present in builder yet!", link_name.c_str());
208 urdf::InertialSharedPtr inertial(
new urdf::Inertial);
209 inertial->origin.position = urdf::Vector3(origin.position.x, origin.position.y, origin.position.z);
210 inertial->origin.rotation =
211 urdf::Rotation(origin.orientation.x, origin.orientation.y, origin.orientation.z, origin.orientation.w);
212 inertial->mass = mass;
220 urdf::LinkSharedPtr link;
222 link->inertial = inertial;
226 geometry_msgs::Pose origin)
228 urdf::VisualSharedPtr vis(
new urdf::Visual);
229 urdf::BoxSharedPtr geometry(
new urdf::Box);
230 geometry->dim = urdf::Vector3(size[0], size[1], size[2]);
231 vis->geometry = geometry;
236 geometry_msgs::Pose origin)
238 if (dims.size() != 3)
240 ROS_ERROR(
"There can only be 3 dimensions of a box (given %zu!)", dims.size());
244 urdf::CollisionSharedPtr coll(
new urdf::Collision);
245 urdf::BoxSharedPtr geometry(
new urdf::Box);
246 geometry->dim = urdf::Vector3(dims[0], dims[1], dims[2]);
247 coll->geometry = geometry;
252 geometry_msgs::Pose origin)
254 urdf::CollisionSharedPtr coll(
new urdf::Collision);
255 urdf::MeshSharedPtr geometry(
new urdf::Mesh);
256 geometry->filename = filename;
257 coll->geometry = geometry;
262 geometry_msgs::Pose origin)
266 ROS_ERROR_NAMED(LOGNAME,
"Link %s not present in builder yet!", link_name.c_str());
270 collision->origin.position = urdf::Vector3(origin.position.x, origin.position.y, origin.position.z);
271 collision->origin.rotation =
272 urdf::Rotation(origin.orientation.x, origin.orientation.y, origin.orientation.z, origin.orientation.w);
274 urdf::LinkSharedPtr link;
276 link->collision_array.push_back(collision);
280 geometry_msgs::Pose origin)
284 ROS_ERROR_NAMED(LOGNAME,
"Link %s not present in builder yet!", link_name.c_str());
288 vis->origin.position = urdf::Vector3(origin.position.x, origin.position.y, origin.position.z);
289 vis->origin.rotation =
290 urdf::Rotation(origin.orientation.x, origin.orientation.y, origin.orientation.z, origin.orientation.w);
292 urdf::LinkSharedPtr link;
294 if (!link->visual_array.empty())
296 link->visual_array.push_back(vis);
298 else if (link->visual)
300 link->visual_array.push_back(link->visual);
301 link->visual.reset();
302 link->visual_array.push_back(vis);
311 const std::string& type,
const std::string& name)
315 new_virtual_joint.
name_ = parent_frame +
"-" + child_link +
"-virtual_joint";
317 new_virtual_joint.
name_ = name;
318 new_virtual_joint.
type_ = type;
321 srdf_writer_->virtual_joints_.push_back(new_virtual_joint);
328 new_group.
name_ = base_link +
"-" + tip_link +
"-chain-group";
330 new_group.
name_ = name;
331 new_group.
chains_.push_back(std::make_pair(base_link, tip_link));
336 const std::string& name)
339 new_group.
name_ = name;
346 const std::string& parent_group,
const std::string& component_group)
364 std::map<std::string, std::string> parent_link_tree;
365 parent_link_tree.clear();
371 catch (urdf::ParseError& e)
382 catch (urdf::ParseError& e)
moveit::core::RobotModelPtr build()
Builds and returns the robot model added to the builder.
bool is_valid_
Whether the current builder state is valid. If any 'add' method fails, this becomes false...
Core components of MoveIt!
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &robot_name)
Loads a robot from moveit_resources.
std::vector< std::pair< std::string, std::string > > chains_
RobotModelBuilder(const std::string &name, const std::string &base_link_name)
Constructor, takes the names of the robot and the base link.
void addGroup(const std::vector< std::string > &links, const std::vector< std::string > &joints, const std::string &name)
Adds a new group using a list of links and a list of joints.
Definition of a kinematic model. This class is not thread safe, however multiple instances can be cre...
urdf::ModelInterfaceSharedPtr urdf_model_
The URDF model, holds all of the URDF components of the robot added so far.
std::string parent_frame_
void addVirtualJoint(const std::string &parent_frame, const std::string &child_link, const std::string &type, const std::string &name="")
Adds a virtual joint to the SRDF.
srdf::SRDFWriterPtr srdf_writer_
The SRDF model, holds all of the SRDF components of the robot added so far.
ROSLIB_DECL std::string getPath(const std::string &package_name)
std::vector< std::string > links_
const std::string LOGNAME
bool isValid()
Returns true if the building process so far has been valid.
std::shared_ptr< Model > ModelSharedPtr
void addLinkCollision(const std::string &link_name, const urdf::CollisionSharedPtr &coll, geometry_msgs::Pose origin)
Adds different collision geometries to a link.
void addVisualBox(const std::string &link_name, const std::vector< double > &size, geometry_msgs::Pose origin)
Adds a visual box to a specific link.
std::vector< std::string > joints_
void addEndEffector(const std::string &name, const std::string &parent_link, const std::string &parent_group="", const std::string &component_group="")
#define ROS_ERROR_NAMED(name,...)
urdf::ModelInterfaceSharedPtr loadModelInterface(const std::string &robot_name)
Loads a URDF Model Interface from moveit_resources.
srdf::ModelSharedPtr loadSRDFModel(const std::string &robot_name)
Loads an SRDF Model from moveit_resources.
Main namespace for MoveIt!
void addChain(const std::string §ion, const std::string &type, const std::vector< geometry_msgs::Pose > &joint_origins={}, urdf::Vector3 joint_axis=urdf::Vector3(1.0, 0.0, 0.0))
Adds a chain of links and joints to the builder. The joint names are generated automatically as "<par...
std::string component_group_
void addCollisionBox(const std::string &link_name, const std::vector< double > &dims, geometry_msgs::Pose origin)
Adds a collision box to a specific link.
void addCollisionMesh(const std::string &link_name, const std::string &filename, geometry_msgs::Pose origin)
Adds a collision mesh to a specific link.
std::string parent_group_
void addInertial(const std::string &link_name, double mass, geometry_msgs::Pose origin, double ixx, double ixy, double ixz, double iyy, double iyz, double izz)
void addGroupChain(const std::string &base_link, const std::string &tip_link, const std::string &name="")
Adds a new group using a chain of links. The group is the parent joint of each link in the chain...
void addLinkVisual(const std::string &link_name, const urdf::VisualSharedPtr &vis, geometry_msgs::Pose origin)
Adds different visual geometries to a link.