3 #include <urdf/model.h>
5 #include <tf2/transform_datatypes.h>
6 #include <tf2/LinearMath/Transform.h>
7 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
8 #include <tf2_ros/buffer.h>
10 #include <ros/package.h>
11 #include <ros/console.h>
29 if (geom->type == urdf::Geometry::MESH)
31 urdf::Mesh* mesh =
static_cast<urdf::Mesh*
>(geom.get());
34 ROS_WARN_NAMED(
"robot",
"[gui_server] Robot model error: No mesh geometry defined");
39 if (mesh->filename.substr(0, pkg_prefix.
size()) == pkg_prefix)
42 size_t i_slash = str.
find(
"/");
47 std::string abs_filename = pkg_path +
"/" + rel_filename;
52 ROS_ERROR_STREAM_NAMED(
"robot",
"[gui_server] Could not load mesh shape from '" << abs_filename <<
"'");
55 else if (geom->type == urdf::Geometry::BOX)
57 urdf::Box* box =
static_cast<urdf::Box*
>(geom.get());
60 ROS_WARN_NAMED(
"robot",
"[gui_server] Robot model error: No box geometry defined");
64 double hx = box->dim.x / 2;
65 double hy = box->dim.y / 2;
66 double hz = box->dim.z / 2;
70 else if (geom->type == urdf::Geometry::CYLINDER)
72 urdf::Cylinder* cyl =
static_cast<urdf::Cylinder*
>(geom.get());
75 ROS_WARN_NAMED(
"robot",
"[gui_server] Robot model error: No cylinder geometry defined");
82 else if (geom->type == urdf::Geometry::SPHERE)
84 urdf::Sphere* sphere =
static_cast<urdf::Sphere*
>(geom.get());
87 ROS_WARN_NAMED(
"robot",
"[gui_server] Robot model error: No sphere geometry defined");
104 for (urdf::VisualSharedPtr& vis : link->visual_array)
106 const urdf::GeometrySharedPtr& geom = vis->geometry;
109 ROS_WARN_STREAM_NAMED(
"robot",
"[gui_server] Robot model error: missing geometry for visual in link: '" << link->name <<
"'");
114 const urdf::Pose& o = vis->origin;
115 offset.
t =
geo::Vector3(o.position.x, o.position.y, o.position.z);
124 visual->addShape(*subshape, offset);
171 urdf::Model robot_model;
176 if (!nh.getParam(urdf_rosparam, urdf_xml))
178 ROS_ERROR_STREAM_NAMED(
"robot",
"ROS parameter not set: '" << urdf_rosparam <<
"'.");
182 if (!robot_model.initString(urdf_xml))
184 ROS_ERROR_STREAM_NAMED(
"robot",
"Could not load robot model for '" <<
name <<
".");
189 robot_model.getLinks(links);
191 for (
const urdf::LinkSharedPtr& link : links)
193 if (!link->visual_array.empty())
210 entity_name = link->name;
212 entity_name =
name_ +
"/" + link->name;
218 visual.
color.a = 255;
219 if (link->visual->material_name ==
"Black" || full_link_name ==
"/amigo/base_kinect/openni_camera")
225 else if (link->visual->material_name ==
"White" || link->visual->material_name ==
"amigo_description/white"
226 || link->visual->material_name ==
"amigo_description/bottomcovers")
228 visual.
color.r = 204;
229 visual.
color.g = 204;
230 visual.
color.b = 204;
232 else if (link->visual->material_name ==
"Grey" || link->visual->material_name ==
"amigo_description/aluminium")
234 visual.
color.r = 102;
235 visual.
color.g = 102;
236 visual.
color.b = 102;
238 else if (link->visual->material_name ==
"amigo_description/orange")
240 visual.
color.r = 204;
241 visual.
color.g = 102;
244 else if (link->visual->material_name ==
"amigo_description/logo")
248 visual.
color.b = 102;
252 ROS_INFO_STREAM(
"[gui_server] " << entity_name <<
": " << link->visual->material_name);
256 visual.
shape = shape;
257 visual.
link = full_link_name;
272 return it->second.shape;
295 ed_gui_server_msgs::EntityInfo e;
300 geometry_msgs::TransformStamped ts =
tf_buffer_->lookupTransform(
"map", it->second.link, ros::Time(0));
301 tf2::Stamped<tf2::Transform>
t;
310 e.color = it->second.color;
312 e.visual_revision = 1;
316 catch (tf2::TransformException& ex)
318 ROS_DEBUG_STREAM_NAMED(
"robot",
"[gui_server] No transform from 'map' to '" << it->second.link <<
"': " << ex.what());