Tutorial1
一 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的更多相关文章
- JavaFX 教程资料收集
1. JavaFX中文资料 http://www.javafxchina.net/blog/docs/tutorial1/ 2. JavaFX入门教程 http://www.xrpmoon.com/c ...
- RDF和Jena RDF API简介
这是官方文章<An Introduction to RDF and the Jena RDF API>的译文.原文是在刺猬的温驯这里看到的.其中的图片没法显示了,还有一段丢失了.于是我在此 ...
- Redis 学习笔记续
Redis - 数据类型 Redis支持5种类型的数据类型,它描述如下的: 字符串 Redis字符串是字节序列.Redis字符串是二进制安全的,这意味着他们有一个已知的长度没有任何特殊字符终止,所以你 ...
- React JS快速入门教程
翻译至官方文档<Tutorial>http://facebook.github.io/react/docs/tutorial.html 转载请注明出处:http://blog.csdn.n ...
- 使用MyBatis Generator生成DAO
虽然MyBatis很方便,但是想要手写全部的mapper还是很累人的,好在MyBatis官方推出了自动化工具,可以根据数据库和定义好的配置直接生成DAO层及以下的全部代码,非常方便. 需要注意的是,虽 ...
- Scalding初探之二:动手来做做小实验
输入文件 Scalding既可以处理HDFS上的数据,也可以很方便地在本地运行处理一些test case便于debug,Source有好多种 1 TextLine(filename) TextLine ...
- C++混合编程之idlcpp教程Python篇(3)
上一篇 C++混合编程之idlcpp教程Python篇(2) 是一个 hello world 的例子,仅仅涉及了静态函数的调用.这一篇会有新的内容. 与PythonTutorial0相似,工程Pyth ...
- C++混合编程之idlcpp教程Lua篇(3)
上一篇 C++混合编程之idlcpp教程Lua篇(2) 是一个 hello world 的例子,仅仅涉及了静态函数的调用.这一篇会有新的内容. 与LuaTutorial0相似,工程LuaTutoria ...
- jQuery 图片剪裁插件初探之 Jcrop
主页:http://deepliquid.com/content/Jcrop.html 官方下载地址:http://deepliquid.com/content/Jcrop_Download.html ...
随机推荐
- loj6038「雅礼集训 2017 Day5」远行 树的直径+并查集+LCT
题目传送门 https://loj.ac/problem/6038 题解 根据树的直径的两个性质: 距离树上一个点最远的点一定是任意一条直径的一个端点. 两个联通块的并的直径是各自的联通块的两条直径的 ...
- LocalDateTime用法(jdk1.8 )
前言 最近看别人项目源码,发现Java8新的日期时间API很方便强大,所以转载该入门介绍博客,记录一下. 使用新时间日期API的必要性 在java8以前,或许: 当你在做有关时间日期的操作时,你会想到 ...
- NLP第一周
19-21周,每周学习15小时以上 基础:Python编程基础:基础的概览统计.了解线性代数:足够的时间投入. 完成9个课程项目,每个5小时-15小时 完成聊天机器人项目(40-80小时) Capst ...
- 对Promise的研究3
Promise.race() Promise.race方法同样是将多个 Promise 实例,包装成一个新的 Promise 实例. const p = Promise.race([p1, p2, p ...
- 一个能极大提高生产率的Chrome新建标签页扩展
我是一个对开发生产率有着BT需求的程序员,总是追求将自己的单位时间生产率最大化. 通过分析,我发现自己一天会反反复复使用Chrome的新建标签,然后访问常用的网站.因此,我期望新建一个默认的Chrom ...
- Dubbo学习-7-dubbo配置文件优先级
Dubbo配置加载流程 根据驱动方式的不同(比如Spring或裸API编程)配置形式上肯定会有所差异,具体参考XML配置.Annotation配置.API配置三篇文档.除了外围驱动方式上的差异,Dub ...
- Python3解leetcode Count Binary Substrings
问题描述: Give a string s, count the number of non-empty (contiguous) substrings that have the same numb ...
- php长连接和短连接的使用场景
短连接 连接->传输数据->关闭连接 比如HTTP是无状态的的短链接,浏览器和服务器每进行一次HTTP操作,就建立一次连接,但任务结束就中断连接. 具体就是 浏览器client发起并建立T ...
- eclipse 启动 tomcat 报错:Server mylocalhost was unable to start within 45 seconds
这个专门转载一篇博文也是为了讽刺一下自己二逼的程序员职业,哈哈. eclipse启动tomcat服务器报错:Server mylocalhost was unable to start within ...
- Javascript中this、prototype、constructor的理解(转载)
http://www.cnblogs.com/phpmix/articles/1734031.html