tf教程(一):Introduction to tf
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:
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-indigo-ros-tutorials ros-indigo-geometry-tutorials ros-indigo-rviz ros-indigo-rosbash ros-indigo-rqt-tf-tree
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:
-
Transform Listener initing Listening to /tf for 5.000000 seconds Done Listening dot - Graphviz version 2.16 (Fri Feb 8 12:52:03 UTC 2008) Detected dot version 2.16 frames.pdf generated
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.
Usage:
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.
Usage:
rosrun tf tf_echo [reference_frame] [target_frame]
Let's look at the transform of the turtle(龟)2 frame with respect to turtle1 frame which is equivalent(等价的) to :
$ rosrun tf tf_echo turtle1 turtle2
You will see the transform displayed as the tf_echo listener receives the frames broadcast over ROS.
-
At time 1416409795.450 - Translation: [0.000, 0.000, 0.000] - Rotation: in Quaternion [0.000, 0.000, 0.914, 0.405] in RPY [0.000, -0.000, 2.308] At time 1416409796.441 - Translation: [0.000, 0.000, 0.000] - Rotation: in Quaternion [0.000, 0.000, 0.914, 0.405] in RPY [0.000, -0.000, 2.308] At time 1416409797.450 - Translation: [0.000, 0.000, 0.000] - Rotation: in Quaternion [0.000, 0.000, 0.914, 0.405] in RPY [0.000, -0.000, 2.308] At time 1416409798.441 - Translation: [0.000, 0.000, 0.000] - Rotation: in Quaternion [0.000, 0.000, 0.914, 0.405] in RPY [0.000, -0.000, 2.308] At time 1416409799.433 - Translation: [0.000, 0.000, 0.000] - Rotation: in Quaternion [0.000, 0.000, 0.691, 0.723] in RPY [0.000, -0.000, 1.526]
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
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.