ROS学习笔记之——ROS之tf变换

82 篇文章 118 订阅

对于基于ROS的定位导航而言,特别是多传感器数据的融合,坐标的变换是非常重要的

 

什么是tf

tf is a package that lets the user keep track of multiple coordinate frames over time. tf maintains the relationship between coordinate frames in a tree structure buffered in time, and lets the user transform points, vectors, etc between any two coordinate frames at any desired point in time.

tf即机器人中多个参考系的坐标变换。可以让多个进程不必各自记录坐标转换关系,对系统中的所有涉及到的坐标转换关系,统一管理。

一个机器人系统通常有很多三维的参考系,而且会随着时间的推移发生变化,例如全局参考系(world frame),机器人中心参考系(base frame),机械夹参考系(gripper frame),机器人头参考系(head frame)等等。tf可以以时间为轴,跟踪这些参考系(默认是10秒之内的),并且允许用户提出如下的申请:

  • 五秒钟之前,机器人头参考系相对于全局参考系的关系是什么样的?
  • 机器人夹取的物体相对于机器人中心参考系的位置在哪里?
  • 机器人中心参考系相对于全局参考系的位置在哪里?

        tf可以在分布式系统中进行操作,也就是说一个机器人系统中所有的参考系变换关系,对于所有节点组件,都是可用的,所有订阅tf消息的节点都会缓冲一份所有参考系的变换关系数据,所以这种结构不需要中心服务器来存储任何数据

 

ROS中,tf算是一个基本的数据类型

tf::Quaternion 四元数,表示一个姿态。

tf::Vector3 三维向量

tf::Point 位置。

tf::Pose 位姿(位置+姿态)成员getRotation()或getBasis()用于获取旋转矩阵;成员getOffset()用于获取平移向量。

tf::Transform 一个坐标转换。成员有:Matrix3x3 m_basis,用3*3的矩阵表示旋转;Vector3 m_origin,用3*1的向量表示平移。

 

ROS中tf设计

http://wiki.ros.org/tf/Design

 

tf相关demo

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

首先开启roscore,注意要在本机运行的话要配置网络,请参考博文《学习笔记之——利用Gazebo仿真TurtleBot3

运行

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.

选择对应的终端,然后通过上下左右来控制乌龟,会发现无论怎么控制,另外一只乌龟都会跟随

This demo is using the tf library to create three coordinate frames: a world frame, a turtle1 frame, and a turtle2 frame(世界帧、turtle1帧和turtle2帧). 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所发布的消息

rosrun tf view_frames

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.

通过运行下面命令也可以查看

rosrun rqt_tf_tree rqt_tf_tree

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

rosrun tf tf_echo turtle1 turtle2

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

 

 

 

 

 

参考资料:

http://www.guyuehome.com/279

https://zhuanlan.zhihu.com/p/55903120

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值