ROS进二阶学习笔记(1) TF 学习笔记1-TF介绍 + tf工具

ROS进二阶学习笔记(1) TF 学习笔记1-TF介绍 + tf工具

ROS进二阶学习笔记(1) TF 学习笔记1: – TF介绍 + tf工具

Ref:  http://wiki.ros.org/tf/Tutorials#Learning_tf

Ref:  http://wiki.ros.org/tf/Tutorials/Introduction%20to%20tf

惭愧的是,时隔10个月,重新来学习tf的东西。

1. 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

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. 关于这个demo,解释一下:

  • demo 用了tf library

  • 建立了3个frame: a world frame, a turtle1 frame, and a turtle2 frame

  • 一个tf broadcaster : publish the turtle coordinate frames

  • 一个tf listener:

    • compute the difference in the turtle frames
    • move one turtle to follow the other

就做了上述的几件事情。

开始剖析具体使用tf来做这个demo的步骤之前,先了解一下TF Tools

2. tf Tools

We can use tf tools to look at what tf is doing behind the scenes. 用tf tools来看看背后的tf在怎么工作:

  • view_frames
  • rqt_tf_tree –rosrun rqt_tf_tree rqt_tf_tree
  • tf_echo – 打印具体tf数据出来
  • rviz + tf

2.1 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


![](http://wiki.ros.org/tf/Tutorials/Introduction%20to%20tf?action=AttachFile&do=get&target=view_frames_2.png)
* see thatworld is the parent of the turtle1 and turtle2 frames
* 


  
 



#### 2.2 Using rqt\_tf\_tree




[rqt\_tf\_tree](http://wiki.ros.org/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](http://wiki.ros.org/rqt_tf_tree) fromPlugins tab.
  

![](http://wiki.ros.org/tf/Tutorials/Introduction%20to%20tf?action=AttachFile&do=get&target=snapshot_rqt_tree_turtle_tf.png)  
 


  
 



#### 2.3 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 turtle2 frame with respect to turtle1 frame which is equivalent to  :![](http://wiki.ros.org/tf/Tutorials/Introduction%20to%20tf?action=AttachFile&do=get&target=latex_986fed48f3e5bc349f7ca256812c18ebe46a588b_p1.png)

$ 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. 我认为重点就是要理解这个tf_echo命令出来的数据具体是什么含义。这个有点矩阵的意思。

这里就是 rosrun tf tf_echo frameA freameB 命令,输出的是: B 相对于 A 的坐标。T1_2 = T1_o * To_2  (Ta_b的几何意义是:b走Ta_b将到达a)

这里最容易搞混。后面还会有更多的内容来帮助理解。

2.3 Using rviz + tf

Let’s look at our turtle frames using rviz. Let’s startrviz with the turtle_tf configuration file using the-d option forrviz:
这里你要看tf在rviz里的话,得先有一个配置文件: turtle_tf

$ rosrun rviz rviz -d `rospack find turtle_tf`/rviz/turtle_rviz.rviz
  • In the side bar , see the frames broadcast by tf

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

Published At
comments powered by Disqus