Wiki

Page

User

Note: This tutorial assumes you are comfortable with using roscpp, and have gone through the ROS Tutorials.

Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Intro

Unlike other displays, the Marker Display lets you visualize data in rviz without rviz knowing anything about interpreting that data. Instead, primitive objects are sent to the display through visualization_msgs/Marker messages, which let you show things like arrows, boxes, spheres and lines.

This tutorial will show you how to send the four basic shapes (boxes, spheres, cylinders, and arrows). We'll create a program that sends out a new marker every second, replacing the last one with a different shape.

Here we create an integer to keep track of what shape we're going to publish. The four types we'll be using here all use the visualization_msgs/Marker message in the same way, so we can simply switch out the shape type to demonstrate the four different shapes.

This begins the meat of the program. First we create a visualization_msgs/Marker, and begin filling it out. The header here is a roslib/Header, which should be familiar if you've done the tftutorials. We set the frame_id member to /my_frame as an example. In a running system this should be the frame relative to which you want the marker's pose to be interpreted.

This type field is what specifies the kind of marker we're sending. The available types are enumerated in the visualization_msgs/Marker message. Here we set the type to our shape variable, which will change every time through the loop.

The action field is what specifies what to do with the marker. The options are visualization_msgs::Marker::ADD and visualization_msgs::Marker::DELETE. ADD is something of a misnomer, it really means "create or modify".

New in Indigo A new action has been added to delete all markers in the particular Rviz display, regardless of ID or namespace. The value is 3 and in future ROS version the message will change to have value visualization_msgs::Marker::DELETEALL.

Running the Code

Viewing the Markers

Now that you're publishing markers, you need to set rviz up to view them. First, make sure rviz is built:

rosmake rviz

Now, run rviz:

rosrun using_markers basic_shapes
rosrun rviz rviz

If you've never used rviz before, please see the User's Guide to get you started.

The first thing to do, because we don't have any tf transforms setup, is to set the Fixed Frames to the frame we set the marker to above, /my_frame. In order to do so, set the Fixed Frame field to "/my_frame".

The first thing to do, because we don't have any tf transforms setup, is to set the Fixed Frames to the frame we set the marker to above, /my_frame. In order to do so, expand ".Global Options" in "Displays" area so that you'll see Fixed Frame fields. Then type in "/my_frame" into it.

The first thing to do, because we don't have any tf transforms setup, is to set both the Fixed and Target Frames to the frame we set the marker to above, /my_frame. In order to do so, first expand ".Global Options" in "Displays" area so that you'll see both "{ Fixed, Target } Frame" fields. Then type in "/my_frame" into each field.

The first thing to do, because we don't have any tf transforms setup, is to set both the Fixed and Target Frames to the frame we set the marker to above, /my_frame. In order to do so, first expand ".Global Options" in "Displays" area so that you'll see both "{ Fixed, Target } Frame" fields. Then type in "/my_frame" into each field.

Next add a Markers display. Notice that the default topic specified, visualization_marker, is the same as the one being published.

You should now see a marker at the origin that changes shape every second:

More Information

For more information on the different types of markers beyond the ones shown here, please see the Markers Display Page