前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ROS2学习tf2坐标变换

ROS2学习tf2坐标变换

作者头像
zhangrelay
发布2019-09-18 15:21:40
2.1K0
发布2019-09-18 15:21:40
举报

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://cloud.tencent.com/developer/article/1508808

坐标变换tf2对于发布各类传感器消息非常重要。一些环境辨识相关的传感器都是含有坐标信息,其位置与机器人的关系,对应到机器人对环境的感知,就需要坐标变换。

参考文献:

Using tf2 with ROS 2 在ROS 2中使用tf2

There is preliminary support for tf2 in ROS 2. We rely heavily on tf2 in ROS 1 to manage data about coordinate transforms, and we expect to continue to use extensively in ROS 2. ROS 2中有tf2的初步支持。依赖ROS 1中的tf2来管理坐标变换的数据,期望继续在ROS 2中广泛使用。

Here’s how to try it out. In each shell, be sure to start by sourcing the ROS 2 setup file as usual 如何使用它?在每个shell中,一定要像往常一样导入ROS 2安装文件环境(例如在Linux 或Windows上分别如下)。

(e.g. on Linux . ~/ros2_ws/install/setup.bash or on Windows call C:\dev\ros2\install\setup.bat).

Publishing transform data 发布变换数据

First run the static_transform_publisher to generate tf2 data: 首先运行static_transform_publisher以生成tf2数据:

代码语言:javascript
复制
ros2 run tf2_ros static_transform_publisher 1 2 3 0.5 0.1 -1.0 foo bar

That tool will publish a static transform from the parent frame foo to the child frame bar with (X, Y, Z) translation (1, 2, 3) and (roll, pitch, yaw) rotation (0.5, 0.1, -1.0). 该工具将发布从父帧foo到子帧bar的静态变换,其中(X,Y,Z)平移(1,2,3)和(滚动,俯仰,偏航)旋转(0.5,0.1,-1.0)。

Receiving transform data 接收变换数据

Now we can check whether it’s possible to receive that transform data with tf2_echo: 现在检查是否可以接收转换数据, 使用tf2_echo

代码语言:javascript
复制
ros2 run tf2_ros tf2_echo foo bar

You should see repeated output similar to this: 应该看到类似于此的重复输出:

代码语言:javascript
复制
At time 0.0
- Translation: [1.000, 2.000, 3.000]
- Rotation: in Quaternion [-0.475, -0.076, 0.240, 0.843]

Note that tf2_echo is reporting the rotation as a quaternion as opposed to roll, pitch, and yaw. 请注意,tf2_echo将旋转角度输出为四元数而不是滚动,俯仰和偏航。


以上是基本概念,具体如何使用呢?遇到问题如何进行排查呢?来看一个案例吧:

在学习这个案例之前,需要先了解Gazebo,详细内容可以参考:Gazebo和ROS2的使用说明(部分翻译)

打开一个gazebo环境,查看其中传感器数据:

gazebo --verbose /opt/ros/dashing/share/gazebo_plugins/worlds/gazebo_ros_ray_sensor_demo.world

gazebo

如果不支持gpu会报如下警告,编写代码时请避免使用gpu规范的虚拟传感器!

Wrn Conversion of sensor typegpu_ray not supported.

启动环境

复习一下ros2 topic指令和rqt_gui:

$ ros2 topic list

/clock

/gpu_ray/laserscan

/gpu_ray/parameter_events

/gpu_ray/pointcloud

/gpu_ray/pointcloud2

/gpu_ray/range

/gpu_ray/rosout

/parameter_events

/ray/laserscan

/ray/parameter_events

/ray/pointcloud

/ray/pointcloud2

/ray/range

/ray/rosout

/rosout

打开rviz2,查看数据可视化:

rviz2

这时候,rviz2中什么也没有,还有一个黄色警告。

tf数据没有,map坐标应该也是不对的。怎么办?先看看,激光的坐标吧?

使用ros2 topic echo,当然也可以查看源码确定具体坐标名称:

ray_link

laser no

依旧啥也没有,然后呢?还是有黄色警告。

显示可视化,需要勾选unreliable!

laser yes

消除警告使用:

代码语言:javascript
复制
ros2 run tf2_ros static_transform_publisher 0 0 0 0 0 0 world ray_link

point

最后合起来看一下:

gazebo

rviz2

gazebo

rviz

结合odom、imu等信息和slam算法,就可以建环境地图,并使用navigation2导航了。

下面再看一下,真实传感器的数据吧。预习链接:ROS2使用lidar激光雷达(rplidar和ydlidar)

终端

scan可视化

机器人建立环境地图和导航案例,稍后补充~

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年09月05日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Using tf2 with ROS 2 在ROS 2中使用tf2
    • Publishing transform data 发布变换数据
      • Receiving transform data 接收变换数据
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档