rviz2 for tf2#

Warning

This topic is under construction and this might not even be its final form. Please feel free to open an issue if you spot any typos or other problems.

rviz2 Installation#

rviz2 has already been installed in ROS2 Installation.

What is rviz2?#

Possibly the easiest description for rviz2, available from ros2/rviz, is ROS 3D Robot Visualizer.

Given that rviz2 lacks any integration with simulation engines, it wouldn’t be usually called a robotics simulator. Nonetheless, for most robotics applications in their initial stages of development, a visualization is an important step forward.

Using rviz2 with tf2#

One interesting capability of rviz2 is the visualization of tf2 in a relatively friendly manner. We can test that quickly with the tf2 example we developed in the previous section.

Up until now, I showered you with equations that you might or might not have understood. After showing you how it works in rviz2, hopefully you will begin to believe me.

From our previous example of tf2.

ros2 run python_package_that_uses_tf2 tf2_broadcaster_node

We run rviz2 with the following command.

ros2 run rviz2 rviz2

The user interface of rviz2 should appear. However, it still does not know what you are trying to do with it, so we will make two modifications to be able to visualize the output of our tf2_broadcaster_node.

  1. In Displays ‣ Fixed Frame, we change the text from map to world.

  2. Then, we add the tf2 visualisation with the sequence Add ‣ rviz_default_plugins ‣ TF.

Note

Starting rviz2 with the following command allows you to skip the first step.

ros2 run rviz2 rviz2 -f world

This is summarised in the video below.

This should be enough to start showing the frames. Using the mouse, can you zoom in and rotate the window to focus on the transforms of interest.

If everything worked as expected, you should see a robot_1 frame rotating about a world frame. Now, you can easily visualize the frames indicating that the frame marked by robot_1 indeed moves in circles, with the rotational frame also rotating in the same frequency.

With these settings, additional broadcast transforms will also be visible. Using rviz2 menus, you can filter the transforms that are relevant for you at any given point.

Other visualisation tools#

Depending on the sensorial information, rviz2 can be the correct tool. It is important, however, to know that it is not the only tool. One convenient tool for visualizing images is rqt_image_view.

The integrated sample can be executed as follows.

Danger

Please note that the (Lena or Lenna) image has been banned by most publishers. Do not use it in your reports or conference submissions. This is part of the integrated sample, therefore shown here, but this usage is not endorsed or recommended.

Nature:

We would like to let our authors, reviewers and readers know that, with immediate effect, we no longer consider submissions containing the Lena (sometimes ‘Lenna’) image. This decision was taken in consultation with relevant journal editors and affects all Nature Research journals.

IEEE:

Lena Image

IEEE’s diversity statement and supporting policies such as the IEEE Code of Ethics speak to IEEE’s commitment to promoting an inclusive and equitable culture that welcomes all. In alignment with this culture and with respect to the wishes of the subject of the image, Lena Forsén, IEEE will no longer accept submitted papers which include the “Lena image.”

ros2 run rqt_image_view image_publisher
ros2 run rqt_image_view rqt_image_view /images

It should work by showing color variations of the controversial image. We will use the visualiser, not the publisher, in some examples in future sections.