[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes you have a working knowledge of compiling programs in ROS. Check out the ROS tutorials to learn how to do this.
(!) 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.

Introduction to tf

Description: This tutorial will give you a good idea of what tf can do for you. It shows off some of the tf power in a multi-robot example using turtlesim. This also introduces using tf_echo, view_frames, rqt_tf_tree, and rviz.

Keywords: transforms, coordinate frames

Tutorial Level: BEGINNER

Next Tutorial: Writing a tf broadcaster (Python) (C++)

Select which version of this tutorial you want:   Show EOL distros: 

Select which buildsystem you are using:

Set Up the Demo

The nodes for this tutorial are released for Ubuntu, so go ahead and install them:

$ sudo apt-get install ros-$ROS_DISTRO-ros-tutorials ros-$ROS_DISTRO-geometry-tutorials ros-$ROS_DISTRO-rviz ros-$ROS_DISTRO-rosbash ros-$ROS_DISTRO-rqt-tf-tree

Let's start by getting any necessary packages and dependencies and compiling the demo package.

$ sudo apt-get install ros-$ROS_DISTRO-geometry-tutorials 
$ rosdep install turtle_tf rviz
$ rosmake turtle_tf rviz

Running the Demo

Now that we're done getting the turtle_tf tutorial package, let's run the demo.

$ roslaunch turtle_tf turtle_tf_demo.launch

You will see the turtlesim start with two turtles.

(in case you experience that a process dies, a workaround is available.)

Once the turtlesim is started you can drive the center turtle around in the turtlesim using the keyboard arrow keys, select the roslaunch terminal window so that your keystrokes will be captured to drive the turtle.

As you can see that one turtle will continuously move to follow the turtle you are driving around.

What is Happening

This demo is using the tf library to create three coordinate frames: a world frame, a turtle1 frame, and a turtle2 frame. This tutorial uses a tf broadcaster to publish the turtle coordinate frames and a tf listener to compute the difference in the turtle frames and move one turtle to follow the other.

tf Tools

Now let's look at how tf is being used to create this demo. We can use tf tools to look at what tf is doing behind the scenes.

Using view_frames

view_frames creates a diagram of the frames being broadcast by tf over ROS.

$ rosrun tf view_frames

You will see:

Here a tf listener is listening to the frames that are being broadcast over ROS and drawing a tree of how the frames are connected. To view the tree:

$ evince frames.pdf

Here we can see the three frames that are broadcast by tf: the world, turtle1, and turtle2. We can also see that world is the parent of the turtle1 and turtle2 frames. For debugging purposes, view_frames also reports some diagnostic information about when the oldest and most recent frame transforms were received and how fast the tf frame is published to tf.

Using rqt_tf_tree

rqt_tf_tree is a runtime tool for visualizing the tree of frames being broadcast over ROS. You can refresh the tree simply by the refresh bottom in the top-left corner of the diagram.


rosrun rqt_tf_tree rqt_tf_tree

Or simply:

rqt &

Then choose rqt_tf_tree from Plugins tab.

Using tf_echo

tf_echo reports the transform between any two frames broadcast over ROS.


rosrun tf tf_echo [reference_frame] [target_frame]

Let's look at the transform of the turtle2 frame with respect to turtle1 frame which is equivalent to \large{$$\mathbf{T}_{turtle1\_turtle2} =\mathbf{T}_{turtle1\_world} *\mathbf{T}_{world\_turtle2}$$} :

$ rosrun tf tf_echo turtle1 turtle2

You will see the transform displayed as the tf_echo listener receives the frames broadcast over ROS.

As you drive your turtle around you will see the transform change as the two turtles move relative to each other.

rviz and tf

rviz is a visualization tool that is useful for examining tf frames. Let's look at our turtle frames using rviz. Let's start rviz with the turtle_tf configuration file using the -d option for rviz:

$ rosrun rviz rviz -d `rospack find turtle_tf`/rviz/turtle_rviz.rviz

$ rosrun rviz rviz -d `rospack find turtle_tf`/rviz/turtle_rviz.vcg


In the side bar you will see the frames broadcast by tf. As you drive the turtle around you will see the frames move in rviz.

Now that we have examined the turtle_tf_demo, let's look at how to write the broadcaster (Python) (C++) for this demo.

2019-03-16 13:36