Note: This tutorial assumes that you have completed the previous tutorials: Markers: Basic Shapes.
(!) 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.

Markers: Points and Lines (C++)

Description: Teaches how to use the visualization_msgs/Marker message to send points and lines to rviz.

Tutorial Level: BEGINNER

Next Tutorial: Interactive Markers: Getting Started

Intro

In the Markers: Basic Shapes you learned how to send simple shapes to rviz using visualization markers. You can send more than just simple shapes though, and this tutorial will introduce you to the POINTS, LINE_STRIP and LINE_LIST marker types. For a full list of types, see the Marker Display page.

Using Points, Line Strips, and Line Lists

The POINTS, LINE_STRIP and LINE_LIST markers all use the points member of the visualization_msgs/Marker message. The POINTS type places a point at each point added. The LINE_STRIP type uses each point as a vertex in a connected set of lines, where point 0 is connected to point 1, 1 to 2, 2 to 3, etc. The LINE_LIST type creates unconnected lines out of each pair of points, i.e. point 0 to 1, 2 to 3, etc.

Anyway, let's get to the code:

The Code

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

The Code Explained

Now let's break down the code, skipping things that were explained in the previous tutorial. The overall effect created is a rotating helix with lines sticking upwards from each vertex.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

Here we create three visualization_msgs/Marker messages and initialize all of their shared data. We take advantage of the fact that message members default to 0 and only set the w member of the pose.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

We assign three different ids to the three markers. The use of the points_and_lines namespace ensures they won't collide with other broadcasters.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

Here we set the marker types to POINTS, LINE_STRIP and LINE_LIST.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

The scale member means different things for these marker types. The POINTS marker uses the x and y members for width and height respectively, while the LINE_STRIP and LINE_LIST markers only use the x component, which defines the line width. Scale values are in meters.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

Here we set the points to green, the line strip to blue, and the line list to red.

Could not fetch external code from 'https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/indigo-devel/visualization_marker_tutorials/src/points_and_lines.cpp':

We use sine and cosine to generate a helix. The POINTS and LINE_STRIP markers both require only a point for each vertex, while the LINE_LIST marker requires 2.

Viewing the Markers

Set up rviz the same way you did in the last tutorial, which is as follows:

Edit the CMakeLists.txt file in your using_markers package, and add to the bottom:

rosbuild_add_executable(points_and_lines src/points_and_lines.cpp)

Then,

$ rosmake using_markers

add_executable(points_and_lines src/points_and_lines.cpp)
target_link_libraries(points_and_lines ${catkin_LIBRARIES})

Then,

$ catkin_make

Then,

$ rosrun rviz rviz &
$ rosrun using_markers points_and_lines

You should see a rotating helix that looks something like this:

Basic Shapes

Next Steps

The Marker Display page has a list of all the markers and options supported by rviz. Try out some of the other markers!

Wiki: rviz/Tutorials/Markers: Points and Lines (last edited 2015-05-20 07:44:39 by DaikiMaekawa)