一 Introduction to tf2

本部分是关于tf2简单介绍,比如tf2能做什么,并使用一个turtlesim的例子来显示tf2在多机器人中的一些能力.同时也包括一些工具的使用,比如tf2_echo, view_frames, and rviz.

1.安装Demo

sudo apt-get install ros-$ROS_DISTRO-turtle-tf2 ros-$ROS_DISTRO-tf2-tools ros-$ROS_DISTRO-tf

2.Running the Demo

$ roslaunch turtle_tf2 turtle_tf2_demo.launch

看到下面两个turtles,如下

在启动的界面使用方向键来控制中间的turtle运动,会看到另外一个turtle跟随运动.

3.上面都做了什么呢?

在这个demo里面使用tf2库来创建了三个坐标系:世界坐标系,turtle1坐标系,turtle2坐标系.

本教程使用了一个tf2 的broadcaster来发布turtle的坐标系,以及一个tf2 的listener来计算两个turtles坐标系之间的差异.然后移动一个turtle来跟随另一个运动.

4.tf2 工具

4.1 使用view_frames

view_frames创建一个由tf2在ROS中发布的坐标系图标.

$ rosrun tf2_tools view_frames.py

有一个tf2的listener来监听ROS中发布的frames,然后画出由坐标系组成的树型结构:

$ evince frames.pdf

4.2 使用tf_echo

tf_echo得出在ROS中任意两个坐标系之间的transform.

rosrun tf tf_echo [reference_frame] [target_frame]

对于本demo中turtle2相对于trutle1坐标系的一个变换等同于如下:

:

$ rosrun tf tf_echo turtle1 turtle2

二 写代码实现一个tf2的静态broadcaster

1.创建一个包learning_tf2

$ catkin_create_pkg learning_tf2 tf2 tf2_ros roscpp rospy turtlesim

2.怎样来broadcast一个transforms

怎样broadcast坐标系到tf2中.在本例中将broadcast变化中的turtles的坐标系.

创建文件,包的src/static_turtle_tf2_broadcaster.cpp

#include <ros/ros.h>
#include <tf2_ros/static_transform_broadcaster.h>
#include <geometry_msgs/TransformStamped.h>
#include <cstdio>
#include <tf2/LinearMath/Quaternion.h> std::string static_turtle_name; int main(int argc, char** argv)
{
ros::init(argc, argv, "my_static_tf2_broadcaster");
if(argc != )
{
ROS_ERROR("Invalid number of parameters\nusage: static_turtle_tf2_broadcaster child_frame_name x y z roll pitch yaw ");
return -;
}
if(strcmp(argv[], "world") == )
{
ROS_ERROR("Your static turtle name cannot be 'world' ");
return -;
}
static_turtle_name = argv[];
static tf2_ros::StaticTransformBroadcaster static_broadcaster;
geometry_msgs::TransformStamped static_transformStamped;
static_transformStamped.header.stamp = ros::Time::now();
static_transformStamped.header.frame_id ="world";
static_transformStamped.child_frame_id = static_turtle_name;
static_transformStamped.transform.translation.x = atof(argv[]);
static_transformStamped.transform.translation.y = atof(argv[]);
static_transformStamped.transform.translation.z = atof(argv[]);
tf2::Quaternion quat;
quat.setRPY(atof(argv[]), atof(argv[]), atof(argv[])); static_transformStamped.transform.rotation.x = quat.x();
static_transformStamped.transform.rotation.y = quat.y();
static_transformStamped.transform.rotation.z = quat.z();
static_transformStamped.transform.rotation.w = quat.w(); static_broadcaster.sendTransform(static_transformStamped);
ROS_INFO("Spinning until killed publishing %s to world",static_turtle_name.c_str());
ros::spin();
return ;
}

修改CMakeLists.txt文件

add_executable(${PROJECT_NAME}_node src/static_turtle_tf2_broadcaster.cpp)

 target_link_libraries(${PROJECT_NAME}_node
${catkin_LIBRARIES}
)

然后运行之

$ rosrun learning_tf2 static_turtle_tf2_broadcaster mystaticturtle      
rostopic echo /tf_static
transforms:
-
header:
seq:
stamp:
secs:
nsecs:
frame_id: "world"
child_frame_id: "mystaticturtle"
transform:
translation:
x: 0.0
y: 0.0
z: 1.0
rotation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
---

3.发布静态transform的合适方法

在实际的机器人开发使用中,基本不会使用上面的方式来发布静态tf,应该使用一个可执行节点static_transform_publisher来执行,其要么在命令行执行,要么在launch文件中执行.

static_transform_publisher x y z yaw pitch roll frame_id child_frame_id

    Publish a static coordinate transform to tf2 using an x/y/z offset in meters and yaw/pitch/roll in radians. (yaw is rotation about Z, pitch is rotation about Y, and roll is rotation about X). 

static_transform_publisher x y z qx qy qz qw frame_id child_frame_id

    Publish a static coordinate transform to tf2 using an x/y/z offset in meters and quaternion. 

比如

<launch>
<node pkg="tf2_ros" type="static_transform_publisher" name="link1_broadcaster" args="1 0 0 0 0 0 1 link1_parent link1" />
</launch>

Unlike in tf, there is no period argument, and a latched topic is used.

Tutorial1的更多相关文章

  1. JavaFX 教程资料收集

    1. JavaFX中文资料 http://www.javafxchina.net/blog/docs/tutorial1/ 2. JavaFX入门教程 http://www.xrpmoon.com/c ...

  2. RDF和Jena RDF API简介

    这是官方文章<An Introduction to RDF and the Jena RDF API>的译文.原文是在刺猬的温驯这里看到的.其中的图片没法显示了,还有一段丢失了.于是我在此 ...

  3. Redis 学习笔记续

    Redis - 数据类型 Redis支持5种类型的数据类型,它描述如下的: 字符串 Redis字符串是字节序列.Redis字符串是二进制安全的,这意味着他们有一个已知的长度没有任何特殊字符终止,所以你 ...

  4. React JS快速入门教程

    翻译至官方文档<Tutorial>http://facebook.github.io/react/docs/tutorial.html 转载请注明出处:http://blog.csdn.n ...

  5. 使用MyBatis Generator生成DAO

    虽然MyBatis很方便,但是想要手写全部的mapper还是很累人的,好在MyBatis官方推出了自动化工具,可以根据数据库和定义好的配置直接生成DAO层及以下的全部代码,非常方便. 需要注意的是,虽 ...

  6. Scalding初探之二:动手来做做小实验

    输入文件 Scalding既可以处理HDFS上的数据,也可以很方便地在本地运行处理一些test case便于debug,Source有好多种 1 TextLine(filename) TextLine ...

  7. C++混合编程之idlcpp教程Python篇(3)

    上一篇 C++混合编程之idlcpp教程Python篇(2) 是一个 hello world 的例子,仅仅涉及了静态函数的调用.这一篇会有新的内容. 与PythonTutorial0相似,工程Pyth ...

  8. C++混合编程之idlcpp教程Lua篇(3)

    上一篇 C++混合编程之idlcpp教程Lua篇(2) 是一个 hello world 的例子,仅仅涉及了静态函数的调用.这一篇会有新的内容. 与LuaTutorial0相似,工程LuaTutoria ...

  9. jQuery 图片剪裁插件初探之 Jcrop

    主页:http://deepliquid.com/content/Jcrop.html 官方下载地址:http://deepliquid.com/content/Jcrop_Download.html ...

随机推荐

  1. man arch

    ARCH(1)   Linux Programmer?. Manual/Linux程序员手册       ARCH(1) NAME/名称       arch - print machine arch ...

  2. python 日期封装

    import time import datetime import locale class TimeUtil: def __init__(self, curtime=None): self.cur ...

  3. Jenkines邮件中添加图片

    1.在Jenkins的邮件插件 Email-ext中的Default Content内容编写html文件,简单模板如下: <html>  <head>  </head&g ...

  4. Java后端进阶教程

    https://www.cnblogs.com/caoleiCoding/p/6170555.html 传智播客Java Spring框架:https://www.bilibili.com/video ...

  5. UE4开发PSVR游戏流程

    先与sony的开发者关系部建立联系,展示工作室/公司制作PSVR游戏的构想和计划以及制作实力,如果对方觉得你提供的信息具有说服力,则会提供开发者资格,和你签署NDA,给你租借开发机和测试机(免费). ...

  6. MySQL备份之XtraBackup工具使用

    数据库的完整备份 [root@vhost1 ~]# innobackupex --defaults-file=/mysqldata/3306/my.cnf  --user=root   --passw ...

  7. VS code 同步设置与插件

    准备工作:拥有一个github账户,电脑上需安装VSCode.实现同步的功能主要依赖于VSCode插件 "Settings Sync"第一步:安装同步插件Settings Sync ...

  8. openpyxl模块简单入门

    一.openpyxl简介和安装 python 读写 excel 有好多选择,但是,方便操作的库不多,在我尝试了几个库之后,我觉得两个比较方便的库分别是 xlrd/xlwt.openpyxl. 之所以推 ...

  9. Socket错误详解及处理方法

    例如错误代码10061, 说明服务器已经找到,但连接被服务器拒绝, 连接失败原因可能是: 端口号设置错误: 2.服务器没有处于监听状态 (即ServerSocket –>Active=true) ...

  10. 安装mysql数据库-centos7

    mysql官网下载地址:https://dev.mysql.com/downloads/mysql/ 参考安装:https://blog.51cto.com/snowlai/2140451?sourc ...