Robowflex  v0.1
Making MoveIt Easy
robowflex::IO::RVIZHelper Class Reference

RVIZ visualization helper. See Live Visualization with RViz for more information. More...

#include <visualization.h>

Public Member Functions

 RVIZHelper (const RobotConstPtr &robot, const std::string &name="robowflex")
 Constructor. All parameters are placed under /name. This helper puts trajectories under /name/trajectory, scenes under /name/scene, and other markers under /name/markers. The robot description is placed under /name/robot_description. More...
 
Trajectories
void updateTrajectory (const planning_interface::MotionPlanResponse &response)
 Updates the trajectory being visualized. More...
 
void updateTrajectory (const Trajectory &trajectory)
 Updates the trajectory being visualized. More...
 
void updateTrajectory (const robot_trajectory::RobotTrajectoryPtr &trajectory)
 Updates the trajectory being visualized. More...
 
void updateTrajectory (const moveit_msgs::RobotTrajectory &traj, const moveit::core::RobotState &start)
 Updates the trajectory being visualized. More...
 
void updateTrajectories (const std::vector< robot_trajectory::RobotTrajectoryPtr > &trajectories)
 Updates the trajectory being visualized to a list of trajectories. More...
 
void updateTrajectories (const std::vector< planning_interface::MotionPlanResponse > &responses)
 Updates the trajectory being visualized to a list of trajectories. More...
 
void updateTrajectories (const std::vector< TrajectoryPtr > &trajectories)
 Updates the trajectory being visualized to a list of trajectories. More...
 
States
void visualizeState (const robot_state::RobotStatePtr &state)
 Visualizes a robot state. More...
 
void visualizeState (const std::vector< double > &state)
 Visualizes a robot state. More...
 
void visualizeCurrentState ()
 Visualize the current state of the robot. More...
 
Scenes
void removeScene ()
 Removes the scene being visualized. More...
 
void updateScene (const SceneConstPtr &scene)
 Updates the scene being visualized. More...
 
void updatePCD (const sensor_msgs::PointCloud2 &msg)
 Updates the pointcloud being visualized. More...
 
Markers
void addMarker (const visualization_msgs::Marker &marker, const std::string &name="")
 Add a marker message (under the name "name") to the scene. More...
 
void addMarker (double x, double y, double z, const std::string &name="")
 Add a spherical marker (under the name "name") to the scene. More...
 
void addMarker (const Eigen::Vector3d &point, const std::string &name="")
 Add a point (spherical) marker to the scene. More...
 
void addTransformMarker (const std::string &name, const std::string &base_frame, const RobotPose &pose, double scale=1)
 Add a transform marker to the managed list of markers. Displayed after an updateMarkers() call. More...
 
void addGeometryMarker (const std::string &name, const GeometryConstPtr &geometry, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color=color::WHITE)
 Add a marker to the managed list of markers. Displayed after an updateMarkers() call. More...
 
void addArrowMarker (const std::string &name, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale)
 Adds an arrow marker to the managed list of markers. Displayed after an updateMarkers() call. More...
 
void addTextMarker (const std::string &name, const std::string &text, const std::string &base_frame, const RobotPose &pose, double height, const Eigen::Vector4d &color=color::WHITE)
 Adds a text marker to the managed list of markers. Displayed after updateMarkers(). More...
 
void addLineMarker (const std::string &name, const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector4d > &colors, double scale)
 Add a set of lines as markers. More...
 
void addGoalMarker (const std::string &name, const MotionRequestBuilder &request)
 Adds the current goal of the motion request builder as a set of markers in the marker array. More...
 
void addGoalMarker (const std::string &name, const moveit_msgs::MotionPlanRequest &request)
 Adds the current goal of the motion plan request as a set of markers in the marker array. More...
 
void removeAllMarkers ()
 Removes all markers that were added through addMarker(). More...
 
void removeMarker (const std::string &name)
 Removes a marker that was added through addMarker(). More...
 
void updateMarkers ()
 Displays the managed list of markers. Keeps track of whether markers have already been displayed and simply need an update, and removes markers removed by removeMarker(). More...
 

Private Member Functions

void fillMarker (visualization_msgs::Marker &marker, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale) const
 Fills a marker in with some common default information. More...
 

Private Attributes

RobotConstPtr robot_
 Robot being visualized. More...
 
ros::NodeHandle nh_
 Handle for publishing. More...
 
ros::Publisher marker_pub_
 Marker publisher. More...
 
ros::Publisher trajectory_pub_
 Trajectory publisher. More...
 
ros::Publisher scene_pub_
 Scene publisher. More...
 
ros::Publisher pcd_pub_
 Pointcloud publisher. More...
 
ros::Publisher state_pub_
 State publisher. More...
 
std::multimap< std::string, visualization_msgs::Marker > markers_
 Markers to publish. More...
 

Detailed Description

RVIZ visualization helper. See Live Visualization with RViz for more information.

Definition at line 37 of file visualization.h.

Constructor & Destructor Documentation

◆ RVIZHelper()

IO::RVIZHelper::RVIZHelper ( const RobotConstPtr robot,
const std::string name = "robowflex" 
)

Constructor. All parameters are placed under /name. This helper puts trajectories under /name/trajectory, scenes under /name/scene, and other markers under /name/markers. The robot description is placed under /name/robot_description.

Parameters
[in]robotRobot to model with this helper.
[in]nameNamespace to use.

Definition at line 39 of file visualization.cpp.

40  : robot_(robot), nh_("/" + name)
41 {
42  std::string description;
43  robot_->getHandlerConst().getParam(Robot::ROBOT_DESCRIPTION, description);
44  std::string semantic;
45  robot_->getHandlerConst().getParam(Robot::ROBOT_DESCRIPTION + Robot::ROBOT_SEMANTIC, semantic);
46 
47  nh_.setParam(Robot::ROBOT_DESCRIPTION, description);
49 
50  trajectory_pub_ = nh_.advertise<moveit_msgs::DisplayTrajectory>("trajectory", 1);
51  state_pub_ = nh_.advertise<moveit_msgs::DisplayRobotState>("state", 1);
52  scene_pub_ = nh_.advertise<moveit_msgs::PlanningScene>("scene", 1);
53  pcd_pub_ = nh_.advertise<sensor_msgs::PointCloud2>("pcd", 1);
54  marker_pub_ = nh_.advertise<visualization_msgs::MarkerArray>("/visualization_marker_array", 100);
55 }
ros::Publisher marker_pub_
Marker publisher.
ros::Publisher pcd_pub_
Pointcloud publisher.
ros::Publisher scene_pub_
Scene publisher.
ros::Publisher trajectory_pub_
Trajectory publisher.
ros::NodeHandle nh_
Handle for publishing.
RobotConstPtr robot_
Robot being visualized.
ros::Publisher state_pub_
State publisher.
static const std::string ROBOT_DESCRIPTION
Default robot description name.
static const std::string ROBOT_SEMANTIC
Default robot semantic description suffix.
Functions for loading and animating robots in Blender.

Member Function Documentation

◆ addArrowMarker()

void IO::RVIZHelper::addArrowMarker ( const std::string name,
const std::string base_frame,
const RobotPose pose,
const Eigen::Vector4d &  color,
const Eigen::Vector3d &  scale 
)

Adds an arrow marker to the managed list of markers. Displayed after an updateMarkers() call.

Parameters
[in]nameName of the marker.
[in]base_frameBase frame of the pose of the marker.
[in]posePose of the marker.
[in]colorColor of the marker.
[in]scaleThe scale of the marker.

Definition at line 204 of file visualization.cpp.

207 {
208  visualization_msgs::Marker marker;
209  fillMarker(marker, base_frame, pose, color, scale);
210 
211  marker.type = visualization_msgs::Marker::ARROW;
212 
213  addMarker(marker, name);
214 }
void addMarker(const visualization_msgs::Marker &marker, const std::string &name="")
Add a marker message (under the name "name") to the scene.
void fillMarker(visualization_msgs::Marker &marker, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale) const
Fills a marker in with some common default information.

◆ addGeometryMarker()

void IO::RVIZHelper::addGeometryMarker ( const std::string name,
const GeometryConstPtr geometry,
const std::string base_frame,
const RobotPose pose,
const Eigen::Vector4d &  color = color::WHITE 
)

Add a marker to the managed list of markers. Displayed after an updateMarkers() call.

Parameters
[in]nameName of the marker.
[in]geometryGeometry of the marker to create.
[in]base_frameBase frame of the pose of the marker.
[in]posePose of the marker.
[in]colorColor of the marker.

Definition at line 271 of file visualization.cpp.

274 {
275  visualization_msgs::Marker marker;
276 
277  auto scale = geometry->getDimensions();
278  switch (geometry->getType())
279  {
281  marker.type = visualization_msgs::Marker::CUBE;
282  break;
284  marker.type = visualization_msgs::Marker::SPHERE;
285  scale[1] = scale[2] = scale[0]; // Copy radius to other dimensions
286  break;
288  marker.type = visualization_msgs::Marker::CYLINDER;
289  {
290  auto scale2 = scale;
291  scale[0] = scale[1] = 2 * scale2[0]; // Copy radius to first two (x & y)
292  scale[2] = scale2[1];
293  }
294  break;
296  scale[0] = scale[1] = scale[2] = 1; // Meshes are unscalable.
297  if (!geometry->getResource().empty())
298  {
299  marker.type = visualization_msgs::Marker::MESH_RESOURCE;
300  marker.mesh_resource = geometry->getResource();
301  marker.mesh_use_embedded_materials = true;
302  }
303  else if (!geometry->getVertices().empty())
304  {
305  auto msg = geometry->getMeshMsg();
306  marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
307  for (std::size_t i = 0; i < msg.triangles.size(); ++i)
308  {
309  marker.points.push_back(msg.vertices[msg.triangles[i].vertex_indices[0]]);
310  marker.points.push_back(msg.vertices[msg.triangles[i].vertex_indices[1]]);
311  marker.points.push_back(msg.vertices[msg.triangles[i].vertex_indices[2]]);
312  }
313  }
314  break;
315 
316  default:
317  RBX_ERROR("Unsupported geometry for marker.");
318  return;
319  };
320 
321  fillMarker(marker, base_frame, pose, color, scale);
322 
323  addMarker(marker, name);
324 }
@ CYLINDER
Solid primitive cylinder. Uses two dimensions (height, radius).
Definition: geometry.h:47
@ MESH
Mesh. Dimensions scale along x, y, z.
Definition: geometry.h:49
@ BOX
Solid primitive box. Uses three dimensions (x, y, z).
Definition: geometry.h:45
@ SPHERE
Solid primitive sphere. Uses one dimension (radius).
Definition: geometry.h:46
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ addGoalMarker() [1/2]

void IO::RVIZHelper::addGoalMarker ( const std::string name,
const MotionRequestBuilder request 
)

Adds the current goal of the motion request builder as a set of markers in the marker array.

Parameters
[in]nameName of the marker(s).
[in]requestRequest to add goal of as a marker.

Definition at line 421 of file visualization.cpp.

422 {
423  addGoalMarker(name, request.getRequestConst());
424 }
void addGoalMarker(const std::string &name, const MotionRequestBuilder &request)
Adds the current goal of the motion request builder as a set of markers in the marker array.
const planning_interface::MotionPlanRequest & getRequestConst() const
Get a const reference to the currently built motion planning request.
Definition: builder.cpp:538

◆ addGoalMarker() [2/2]

void IO::RVIZHelper::addGoalMarker ( const std::string name,
const moveit_msgs::MotionPlanRequest request 
)

Adds the current goal of the motion plan request as a set of markers in the marker array.

Parameters
[in]nameName of the marker(s).
[in]requestRequest to add goal of as a marker.

Definition at line 326 of file visualization.cpp.

327 {
328  const auto &goals = request.goal_constraints;
329 
330  // Iterate over each goal (an "or"-ing together of different constraints)
331  for (const auto &goal : goals)
332  {
333  auto color = getRandomColor(); // Use the same color for all elements of this goal
334  color[3] = 0.7; // Make slightly transparent
335 
336  for (const auto &pg : goal.position_constraints)
337  {
338  const auto &pname = pg.link_name;
339  const auto &base_frame = pg.header.frame_id;
340 
341  // Get global transform of position constraint
342  RobotPose pose;
343  if (base_frame == robot_->getModelConst()->getModelFrame())
344  {
345  pose.setIdentity();
346  }
347  else
348  {
349  pose = robot_->getLinkTF(pg.header.frame_id);
350  }
351  pose.translate(TF::vectorMsgToEigen(pg.target_point_offset));
352 
353  // Iterate over all position primitives and their poses
354  for (const auto &primitive :
355  boost::combine(pg.constraint_region.primitives, pg.constraint_region.primitive_poses))
356  {
357  shape_msgs::SolidPrimitive solid;
358  geometry_msgs::Pose solid_pose;
359  boost::tie(solid, solid_pose) = primitive;
360 
361  // Compute transform of bounding volume
362  auto frame = pose * TF::poseMsgToEigen(solid_pose);
363 
364  // Add geometry marker associated with this solid primitive
365  addGeometryMarker(name, Geometry::makeSolidPrimitive(solid), base_frame, frame, color);
366 
367  // Iterate over all orientation constraints for the same link as the
368  // position constraint
369  for (const auto &og : goal.orientation_constraints)
370  {
371  const auto &oname = og.link_name;
372  if (oname != pname)
373  continue;
374 
375  auto q = TF::quaternionMsgToEigen(og.orientation);
376 
377  // Arrow display frame.
378  RobotPose qframe = RobotPose::Identity();
379  qframe.translate(frame.translation()); // Place arrows at the origin
380  // of the position volume
381 
382  Eigen::Vector3d scale = {0.1, 0.008, 0.003}; // A nice default size of arrow
383 
384  // Display primary orientation slightly larger
385  addArrowMarker(name, base_frame, qframe * q, color, 1.5 * scale);
386 
387  // Zip together tolerances and axes, and iterate over them to display
388  // orientation bounds
389  const auto tolerances = {og.absolute_x_axis_tolerance, //
390  og.absolute_y_axis_tolerance, //
391  og.absolute_z_axis_tolerance};
392  const auto axes = {Eigen::Vector3d::UnitX(), //
393  Eigen::Vector3d::UnitY(), //
394  Eigen::Vector3d::UnitZ()};
395  for (const auto &angles : boost::combine(tolerances, axes))
396  {
397  double value;
398  Eigen::Vector3d axis;
399  boost::tie(value, axis) = angles;
400 
401  // Show boundaries of tolerances as smaller arrows.
402  auto q1 = TF::offsetOrientation(q, axis, value);
403  addArrowMarker(name, base_frame, qframe * q1, color, scale);
404 
405  auto q2 = TF::offsetOrientation(q, axis, -value);
406  addArrowMarker(name, base_frame, qframe * q2, color, scale);
407  }
408  }
409  }
410 
411  // TODO: Implement
412  // for (const auto &mesh :
413  // boost::combine(pg.constraint_region.meshes,
414  // pg.constraint_region.mesh_poses))
415  // {
416  // }
417  }
418  }
419 }
static GeometryPtr makeSolidPrimitive(const shape_msgs::SolidPrimitive &msg)
Create a solid primitive.
Definition: geometry.cpp:68
void addArrowMarker(const std::string &name, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale)
Adds an arrow marker to the managed list of markers. Displayed after an updateMarkers() call.
void addGeometryMarker(const std::string &name, const GeometryConstPtr &geometry, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color=color::WHITE)
Add a marker to the managed list of markers. Displayed after an updateMarkers() call.
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
Definition: tf.cpp:94
RobotPose poseMsgToEigen(const geometry_msgs::Pose &msg)
Converts a pose message to RobotPose.
Definition: tf.cpp:114
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
Definition: tf.cpp:135
Eigen::Quaterniond offsetOrientation(const Eigen::Quaterniond &orientation, const Eigen::Vector3d &axis, double value)
Offset an orientation by a rotation about an axis.
Definition: tf.cpp:228
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24

◆ addLineMarker()

void IO::RVIZHelper::addLineMarker ( const std::string name,
const std::vector< Eigen::Vector3d > &  points,
const std::vector< Eigen::Vector4d > &  colors,
double  scale 
)

Add a set of lines as markers.

Parameters
[in]nameName of the marker.
[in]pointsPair-wise list of points to add as lines. (eg., 0-1, 2-3, ...)
[in]colorsList of colors for each point.
[in]scaleScale of the marker.

Definition at line 229 of file visualization.cpp.

231 {
232  visualization_msgs::Marker marker;
233 
234  fillMarker(marker, //
235  "map", //
236  RobotPose::Identity(), //
237  getRandomColor(), //
238  Eigen::Vector3d{scale, 1, 1});
239 
240  marker.type = visualization_msgs::Marker::LINE_LIST;
241 
242  if (points.size() != colors.size())
243  throw Exception(1, "Mismatch between points and colors sizes!");
244 
245  for (std::size_t i = 0; i < points.size(); ++i)
246  {
247  marker.points.emplace_back(TF::pointEigenToMsg(points[i]));
248  std_msgs::ColorRGBA mcolor;
249  mcolor.r = colors[i][0];
250  mcolor.g = colors[i][1];
251  mcolor.b = colors[i][2];
252  mcolor.a = colors[i][3];
253  marker.colors.emplace_back(mcolor);
254  }
255 
256  addMarker(marker, name);
257 }
Exception that contains a message and an error code.
Definition: util.h:15
T emplace_back(T... args)
geometry_msgs::Point pointEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a point message.
Definition: tf.cpp:84
T size(T... args)

◆ addMarker() [1/3]

void IO::RVIZHelper::addMarker ( const Eigen::Vector3d &  point,
const std::string name = "" 
)

Add a point (spherical) marker to the scene.

Parameters
[in]pointThe x,y,z coordinates as a vector
[in]nameName of marker.

Definition at line 462 of file visualization.cpp.

463 {
464  addMarker(point.x(), point.y(), point.z(), name);
465 }

◆ addMarker() [2/3]

void IO::RVIZHelper::addMarker ( const visualization_msgs::Marker &  marker,
const std::string name = "" 
)

Add a marker message (under the name "name") to the scene.

Parameters
[in]markerA marker message.
[in]nameName of marker.

Definition at line 440 of file visualization.cpp.

441 {
442  markers_.emplace(name, marker);
443 }
std::multimap< std::string, visualization_msgs::Marker > markers_
Markers to publish.
T emplace(T... args)

◆ addMarker() [3/3]

void IO::RVIZHelper::addMarker ( double  x,
double  y,
double  z,
const std::string name = "" 
)

Add a spherical marker (under the name "name") to the scene.

Parameters
[in]xThe x coordinate of the sphere.
[in]yThe y coordinate of the sphere.
[in]zThe z coordinate of the sphere.
[in]nameName of marker.

Definition at line 445 of file visualization.cpp.

446 {
447  visualization_msgs::Marker marker;
448  const std::string &base_frame = "map";
449 
450  const auto &pose = TF::createPoseXYZ(x, y, z);
451 
452  const auto &scale = Eigen::Vector3d{0.05, 0.05, 0.05};
453  const auto &color = getRandomColor();
454 
455  fillMarker(marker, base_frame, pose, color, scale);
456 
457  marker.type = visualization_msgs::Marker::SPHERE;
458 
459  addMarker(marker, name);
460 }
RobotPose createPoseXYZ(double x, double y, double z)
Creates a robot pose from a linear component and zero orientation.
Definition: tf.cpp:14

◆ addTextMarker()

void IO::RVIZHelper::addTextMarker ( const std::string name,
const std::string text,
const std::string base_frame,
const RobotPose pose,
double  height,
const Eigen::Vector4d &  color = color::WHITE 
)

Adds a text marker to the managed list of markers. Displayed after updateMarkers().

Parameters
[in]nameName of the marker.
[in]textThe text to display.
[in]base_frameBase frame of the pose of the marker.
[in]posePose of the marker.
[in]heightThe height of the text.
[in]colorColor of the marker.

Definition at line 216 of file visualization.cpp.

219 {
220  visualization_msgs::Marker marker;
221  fillMarker(marker, base_frame, pose, color, {0, 0, height});
222 
223  marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
224  marker.text = text;
225 
226  addMarker(marker, name);
227 }

◆ addTransformMarker()

void IO::RVIZHelper::addTransformMarker ( const std::string name,
const std::string base_frame,
const RobotPose pose,
double  scale = 1 
)

Add a transform marker to the managed list of markers. Displayed after an updateMarkers() call.

Parameters
[in]nameName of the marker.
[in]base_frameBase frame of the pose of the marker.
[in]posePose of the transform.
[in]scaleScale factor that controls the size of the frame marker.

Definition at line 259 of file visualization.cpp.

261 {
262  const auto &arrow_size = Eigen::Vector3d{0.1, 0.008, 0.003}; // A nice default size of arrow
263  const auto &z_rot90 = TF::createPoseXYZ(0, 0, 0, 0, 0, constants::half_pi);
264  const auto &y_rot90 = TF::createPoseXYZ(0, 0, 0, 0, -constants::half_pi, 0);
265 
266  addArrowMarker(name + "X", base_frame, pose, color::RED, scale * arrow_size);
267  addArrowMarker(name + "Y", base_frame, pose * z_rot90, color::GREEN, scale * arrow_size);
268  addArrowMarker(name + "Z", base_frame, pose * y_rot90, color::BLUE, scale * arrow_size);
269 }
static const Eigen::Vector4d GREEN
Definition: colormap.h:60
static const Eigen::Vector4d RED
Definition: colormap.h:57
static const Eigen::Vector4d BLUE
Definition: colormap.h:61
static const double half_pi
Definition: constants.h:22

◆ fillMarker()

void IO::RVIZHelper::fillMarker ( visualization_msgs::Marker &  marker,
const std::string base_frame,
const RobotPose pose,
const Eigen::Vector4d &  color,
const Eigen::Vector3d &  scale 
) const
private

Fills a marker in with some common default information.

Parameters
[out]markerMarker to fill.
[in]base_frameBase frame of the pose of the marker.
[in]posePose of the marker.
[in]colorColor of the marker.
[in]scaleThe scale of the marker.

Definition at line 183 of file visualization.cpp.

186 {
187  marker.header.frame_id = base_frame;
188  marker.frame_locked = true;
189 
190  marker.header.stamp = ros::Time().now();
191  marker.ns = "/robowflex";
192  marker.id = markers_.size();
193 
194  marker.action = visualization_msgs::Marker::ADD;
195  marker.pose = TF::poseEigenToMsg(pose);
196  marker.scale = TF::vectorEigenToMsg(scale);
197 
198  marker.color.r = color[0];
199  marker.color.g = color[1];
200  marker.color.b = color[2];
201  marker.color.a = color[3];
202 }
geometry_msgs::Vector3 vectorEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a vector message.
Definition: tf.cpp:104
geometry_msgs::Pose poseEigenToMsg(const RobotPose &pose)
Converts an RobotPose to a pose message.
Definition: tf.cpp:120

◆ removeAllMarkers()

void IO::RVIZHelper::removeAllMarkers ( )

Removes all markers that were added through addMarker().

Definition at line 426 of file visualization.cpp.

427 {
428  for (auto &marker : markers_)
429  marker.second.action = visualization_msgs::Marker::DELETE;
430 }

◆ removeMarker()

void IO::RVIZHelper::removeMarker ( const std::string name)

Removes a marker that was added through addMarker().

Parameters
[in]nameThe name of the marker to remove.

Definition at line 432 of file visualization.cpp.

433 {
434  auto markers = markers_.equal_range(name);
435 
436  for (auto it = markers.first; it != markers.second; ++it)
437  it->second.action = visualization_msgs::Marker::DELETE;
438 }
T equal_range(T... args)

◆ removeScene()

void IO::RVIZHelper::removeScene ( )

Removes the scene being visualized.

Definition at line 467 of file visualization.cpp.

468 {
469  updateScene(nullptr);
470 }
void updateScene(const SceneConstPtr &scene)
Updates the scene being visualized.

◆ updateMarkers()

void IO::RVIZHelper::updateMarkers ( )

Displays the managed list of markers. Keeps track of whether markers have already been displayed and simply need an update, and removes markers removed by removeMarker().

Definition at line 507 of file visualization.cpp.

508 {
509  visualization_msgs::MarkerArray msg;
510 
512  for (auto &marker : markers_)
513  {
514  msg.markers.emplace_back(marker.second);
515 
516  if (marker.second.action == visualization_msgs::Marker::ADD)
517  marker.second.action = visualization_msgs::Marker::MODIFY;
518 
519  else if (marker.second.action == visualization_msgs::Marker::DELETE)
520  remove.push_back(marker.first);
521  }
522 
523  if (marker_pub_.getNumSubscribers() < 1)
524  {
525  RBX_INFO("Waiting for MarkerArray subscribers...");
526 
527  ros::WallDuration pause(0.1);
528  while (marker_pub_.getNumSubscribers() < 1)
529  pause.sleep();
530  }
531 
532  marker_pub_.publish(msg);
533 
534  for (auto &marker : remove)
535  markers_.erase(markers_.find(marker));
536 }
T erase(T... args)
T find(T... args)
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
T remove(T... args)

◆ updatePCD()

void IO::RVIZHelper::updatePCD ( const sensor_msgs::PointCloud2 &  msg)

Updates the pointcloud being visualized.

Parameters
[in]msgPointcloud msg to visualize.

Definition at line 493 of file visualization.cpp.

494 {
495  if (pcd_pub_.getNumSubscribers() < 1)
496  {
497  RBX_INFO("Waiting for pcd subscribers...");
498 
499  ros::WallDuration pause(0.1);
500  while (pcd_pub_.getNumSubscribers() < 1)
501  pause.sleep();
502  }
503 
504  pcd_pub_.publish(msg);
505 }

◆ updateScene()

void IO::RVIZHelper::updateScene ( const SceneConstPtr scene)

Updates the scene being visualized.

Parameters
[in]sceneScene to visualize. If null, removes scene by publishing empty message.

Definition at line 472 of file visualization.cpp.

473 {
474  if (scene_pub_.getNumSubscribers() < 1)
475  {
476  RBX_INFO("Waiting for Scene subscribers...");
477 
478  ros::WallDuration pause(0.1);
479  while (scene_pub_.getNumSubscribers() < 1)
480  pause.sleep();
481  }
482 
483  moveit_msgs::PlanningScene to_pub;
484  if (scene != nullptr)
485  {
486  to_pub = scene->getMessage();
487  to_pub.is_diff = true;
488  }
489 
490  scene_pub_.publish(to_pub);
491 }
Functions for loading and animating scenes in Blender.

◆ updateTrajectories() [1/3]

void IO::RVIZHelper::updateTrajectories ( const std::vector< planning_interface::MotionPlanResponse > &  responses)

Updates the trajectory being visualized to a list of trajectories.

Parameters
[in]responsesPlanning responses to visualize.

Definition at line 127 of file visualization.cpp.

128 {
129  auto moveit_trajectories = std::vector<robot_trajectory::RobotTrajectoryPtr>();
130 
131  for (const auto &response : responses)
132  if (response.error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
133  moveit_trajectories.push_back(response.trajectory_);
134 
135  updateTrajectories(moveit_trajectories);
136 }
void updateTrajectories(const std::vector< robot_trajectory::RobotTrajectoryPtr > &trajectories)
Updates the trajectory being visualized to a list of trajectories.

◆ updateTrajectories() [2/3]

void IO::RVIZHelper::updateTrajectories ( const std::vector< robot_trajectory::RobotTrajectoryPtr > &  trajectories)

Updates the trajectory being visualized to a list of trajectories.

Parameters
[in]trajectoriesVector of MoveIt! robot trajectories to visualize.

Definition at line 96 of file visualization.cpp.

97 {
98  moveit_msgs::DisplayTrajectory out;
99  out.model_id = robot_->getModelName();
100 
101  bool set = false;
102  for (const auto &traj : trajectories)
103  {
104  if (!set)
105  {
106  moveit::core::robotStateToRobotStateMsg(traj->getFirstWayPoint(), out.trajectory_start);
107  set = true;
108  }
109 
110  moveit_msgs::RobotTrajectory msg;
111  traj->getRobotTrajectoryMsg(msg);
112  out.trajectory.push_back(msg);
113  }
114 
115  if (trajectory_pub_.getNumSubscribers() < 1)
116  {
117  RBX_INFO("Waiting for Trajectory subscribers...");
118 
119  ros::WallDuration pause(0.1);
120  while (trajectory_pub_.getNumSubscribers() < 1)
121  pause.sleep();
122  }
123 
124  trajectory_pub_.publish(out);
125 }
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)

◆ updateTrajectories() [3/3]

void IO::RVIZHelper::updateTrajectories ( const std::vector< TrajectoryPtr > &  trajectories)

Updates the trajectory being visualized to a list of trajectories.

Parameters
[in]responsesVector of robowflex trajectories to visualize.

Definition at line 138 of file visualization.cpp.

139 {
140  auto moveit_trajectories = std::vector<robot_trajectory::RobotTrajectoryPtr>();
141 
142  for (const auto &traj : trajectories)
143  moveit_trajectories.push_back(traj->getTrajectory());
144 
145  updateTrajectories(moveit_trajectories);
146 }

◆ updateTrajectory() [1/4]

void IO::RVIZHelper::updateTrajectory ( const moveit_msgs::RobotTrajectory &  traj,
const moveit::core::RobotState start 
)

Updates the trajectory being visualized.

Parameters
[in]trajRobotTrajectory to visualize.
[in]startbase_state to copy values for other joints.

Definition at line 75 of file visualization.cpp.

77 {
78  moveit_msgs::DisplayTrajectory out;
79 
80  out.model_id = robot_->getModelName();
81  out.trajectory.push_back(traj);
82  moveit::core::robotStateToRobotStateMsg(start, out.trajectory_start);
83 
84  if (trajectory_pub_.getNumSubscribers() < 1)
85  {
86  RBX_INFO("Waiting for Trajectory subscribers...");
87 
88  ros::WallDuration pause(0.1);
89  while (trajectory_pub_.getNumSubscribers() < 1)
90  pause.sleep();
91  }
92 
93  trajectory_pub_.publish(out);
94 }

◆ updateTrajectory() [2/4]

void IO::RVIZHelper::updateTrajectory ( const planning_interface::MotionPlanResponse response)

Updates the trajectory being visualized.

Parameters
[in]responsePlanning response to visualize.

Definition at line 57 of file visualization.cpp.

58 {
59  updateTrajectory(response.trajectory_);
60 }
void updateTrajectory(const planning_interface::MotionPlanResponse &response)
Updates the trajectory being visualized.
robot_trajectory::RobotTrajectoryPtr trajectory_

◆ updateTrajectory() [3/4]

void IO::RVIZHelper::updateTrajectory ( const robot_trajectory::RobotTrajectoryPtr &  trajectory)

Updates the trajectory being visualized.

Parameters
[in]trajectoryTrajectory to visualize.

Definition at line 67 of file visualization.cpp.

68 {
69  moveit_msgs::RobotTrajectory msg;
71 
73 }
void getRobotTrajectoryMsg(moveit_msgs::RobotTrajectory &trajectory) const
const robot_state::RobotState & getFirstWayPoint() const
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")

◆ updateTrajectory() [4/4]

void IO::RVIZHelper::updateTrajectory ( const Trajectory trajectory)

Updates the trajectory being visualized.

Parameters
[in]trajectoryTrajectory to visualize.

Definition at line 62 of file visualization.cpp.

63 {
64  updateTrajectory(trajectory.getTrajectoryConst());
65 }

◆ visualizeCurrentState()

void IO::RVIZHelper::visualizeCurrentState ( )

Visualize the current state of the robot.

Definition at line 178 of file visualization.cpp.

179 {
180  visualizeState(robot_->getScratchStateConst());
181 }
void visualizeState(const robot_state::RobotStatePtr &state)
Visualizes a robot state.

◆ visualizeState() [1/2]

void IO::RVIZHelper::visualizeState ( const robot_state::RobotStatePtr &  state)

Visualizes a robot state.

Parameters
[in]stateThe state of the robot to be visualized.

Definition at line 148 of file visualization.cpp.

149 {
150  if (state_pub_.getNumSubscribers() < 1)
151  {
152  RBX_INFO("Waiting for State subscribers...");
153 
154  ros::WallDuration pause(0.1);
155  while (state_pub_.getNumSubscribers() < 1)
156  pause.sleep();
157  }
158 
159  moveit_msgs::DisplayRobotState out;
160  moveit::core::robotStateToRobotStateMsg(*state, out.state);
161 
162  state_pub_.publish(out);
163 }

◆ visualizeState() [2/2]

void IO::RVIZHelper::visualizeState ( const std::vector< double > &  state)

Visualizes a robot state.

Parameters
[in]stateThe state of the robot to be visualized.

Definition at line 165 of file visualization.cpp.

166 {
167  auto state = robot_->allocState();
168 
169  sensor_msgs::JointState joint_state;
170  joint_state.name = robot_->getJointNames();
171  joint_state.position = state_vec;
172 
173  moveit::core::jointStateToRobotState(joint_state, *state);
174 
175  visualizeState(state);
176 }
bool jointStateToRobotState(const sensor_msgs::JointState &joint_state, RobotState &state)

Member Data Documentation

◆ marker_pub_

ros::Publisher robowflex::IO::RVIZHelper::marker_pub_
private

Marker publisher.

Definition at line 250 of file visualization.h.

◆ markers_

std::multimap<std::string, visualization_msgs::Marker> robowflex::IO::RVIZHelper::markers_
private

Markers to publish.

Definition at line 256 of file visualization.h.

◆ nh_

ros::NodeHandle robowflex::IO::RVIZHelper::nh_
private

Handle for publishing.

Definition at line 249 of file visualization.h.

◆ pcd_pub_

ros::Publisher robowflex::IO::RVIZHelper::pcd_pub_
private

Pointcloud publisher.

Definition at line 253 of file visualization.h.

◆ robot_

RobotConstPtr robowflex::IO::RVIZHelper::robot_
private

Robot being visualized.

Definition at line 248 of file visualization.h.

◆ scene_pub_

ros::Publisher robowflex::IO::RVIZHelper::scene_pub_
private

Scene publisher.

Definition at line 252 of file visualization.h.

◆ state_pub_

ros::Publisher robowflex::IO::RVIZHelper::state_pub_
private

State publisher.

Definition at line 254 of file visualization.h.

◆ trajectory_pub_

ros::Publisher robowflex::IO::RVIZHelper::trajectory_pub_
private

Trajectory publisher.

Definition at line 251 of file visualization.h.


The documentation for this class was generated from the following files: