3 #include <kdl_parser/kdl_parser.hpp>
5 #include <ros/node_handle.h>
15 #include <ros/package.h>
39 joint_pos = it_up->second;
46 joint_pos = it_low->second;
51 float p1 = it_low->second;
52 float p2 = it_up->second;
54 float dt1 =
t.seconds() - it_low->first.seconds();
55 float dt2 = it_up->first.seconds() -
t.seconds();
58 joint_pos = (p1 * dt2 + p2 * dt1) / (dt1 + dt2);
78 if (geom->type == urdf::Geometry::MESH)
80 urdf::Mesh* mesh =
static_cast<urdf::Mesh*
>(geom.get());
83 ROS_WARN_NAMED(
"RobotPlugin",
"[RobotPlugin] Robot model error: No mesh geometry defined");
88 if (mesh->filename.substr(0, pkg_prefix.
size()) == pkg_prefix)
91 size_t i_slash = str.
find(
"/");
96 std::string abs_filename = pkg_path +
"/" + rel_filename;
101 ROS_ERROR_STREAM_NAMED(
"RobotPlugin",
"[RobotPlugin] Could not load mesh shape from '" << abs_filename <<
"'");
104 else if (geom->type == urdf::Geometry::BOX)
106 urdf::Box* box =
static_cast<urdf::Box*
>(geom.get());
109 ROS_WARN_NAMED(
"RobotPlugin",
"[RobotPlugin] Robot model error: No box geometry defined");
113 double hx = box->dim.x / 2;
114 double hy = box->dim.y / 2;
115 double hz = box->dim.z / 2;
119 else if (geom->type == urdf::Geometry::CYLINDER)
121 urdf::Cylinder* cyl =
static_cast<urdf::Cylinder*
>(geom.get());
124 ROS_WARN_NAMED(
"RobotPlugin",
"[RobotPlugin] Robot model error: No cylinder geometry defined");
131 else if (geom->type == urdf::Geometry::SPHERE)
133 urdf::Sphere* sphere =
static_cast<urdf::Sphere*
>(geom.get());
136 ROS_WARN_NAMED(
"RobotPlugin",
"[RobotPlugin] Robot model error: No sphere geometry defined");
153 for (urdf::VisualSharedPtr& vis : link->visual_array)
155 const urdf::GeometrySharedPtr& geom = vis->geometry;
158 ROS_WARN_STREAM_NAMED(
"RobotPlugin" ,
"[RobotPlugin] Robot model error: missing geometry for visual in link: '" << link->name <<
"'");
163 const urdf::Pose& o = vis->origin;
164 offset.
t =
geo::Vector3(o.position.x, o.position.y, o.position.z);
173 visual->addShape(*subshape, offset);
176 for (urdf::CollisionSharedPtr& col : link->collision_array)
178 const urdf::GeometrySharedPtr& geom = col->geometry;
181 ROS_WARN_STREAM_NAMED(
"RobotPlugin" ,
"[RobotPlugin] Robot model error: missing geometry for collision in link: '" << link->name <<
"'");
186 const urdf::Pose& o = col->origin;
187 offset.
t =
geo::Vector3(o.position.x, o.position.y, o.position.z);
196 collision->addShape(*subshape, offset);
199 return {visual, collision};
218 const KDL::Segment& segment = it_segment->second.segment;
226 req.
setType(child_id,
"robot_link");
230 boost::shared_ptr<JointRelation> r(
new JointRelation(segment));
244 for (
unsigned int i = 0; i < children.
size(); i++)
252 if (msg->name.size() != msg->position.size())
254 ROS_ERROR(
"[ED RobotPlugin] On joint callback: name and position vector must be of equal length.");
258 for(
unsigned int i = 0; i < msg->name.size(); ++i)
261 double pos = msg->position[i];
272 r->insert(msg->header.stamp.toSec(), pos);
280 ROS_ERROR_STREAM(
"[ED RobotPlugin] On joint callback: unknown joint name '" <<
name <<
"'.");
302 ROS_DEBUG_STREAM(
"[RobotPlugin] Topic: " << topic);
304 ros::SubscribeOptions sub_options = ros::SubscribeOptions::create<sensor_msgs::JointState>
317 if (!nh.getParam(urdf_rosparam, urdf_xml))
319 config.
addError(
"No such ROS parameter: '" + urdf_rosparam +
"'.");
323 if (!kdl_parser::treeFromString(urdf_xml,
tree_))
358 const urdf::LinkSharedPtr& link = *it;
362 if (visual || collision)
365 if (link->name.find(
robot_name_) == std::string::npos)
387 if (e_robot && e_robot->has_pose())
393 req.
setPose(e->id(), e_robot->pose() * tc.transform());