一 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. re正则常用示例积累

    2019-12-7 import re ''' 示例1: 提取网站的网址 ''' urls = ['https://blog.csdn.net/xxcupid/article/details/5199 ...

  2. Django2 + python3 上传图片

    . ├── db.sqlite3 ├── manage.py ├── myImg │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init_ ...

  3. Anaconda概念和使用方法

    Anaconda概述 Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存.切 ...

  4. locate 定位配置文件

    [root@VM_58_118_centos syhuo.net]# locate redis.conf /etc/redis.conf /etc/redis.conf_bak_20191008 /u ...

  5. (转)使用windows server2008 创建 Hyper-V虚拟机

    转:https://jingyan.baidu.com/article/7c6fb42833ad4980652c904f.html Hyper-v是微软提供的虚拟机,利用server 2008搭建hy ...

  6. 1207D Number Of Permutations

    题目大意 给你n个二元组 问你有几种排列是的按两个关键字中的任意一个都不是不降排列的 分析 不妨容斥 我们先加上总的方案数$n!$ 之后我们按第一个关键字排序 因为值相同的情况下不影响答案 所以让总方 ...

  7. :nth-child 与 ;nth-of-child

    //:nth-child:是选择父元素下的第几个元素,不分标签类别,计数从1开始 //:nth-of-type:是选择父元素下的同类型元素的第几个元素.区分标签类别,计数从1开始

  8. 为什么从pycharm中打开的html文件会显示404?

    问题如图: 解决办法: 某次发现运行导入的html文件的时候,打开浏览器会报404错误:而运行自己写的html文件则正常显示:最后发现这是pycharm缓存问题,只需重启pycharm清除缓存就ok啦 ...

  9. mybatis缓存机制(转)

    缓存在互联网系统中是非常重要的, 其主要作用是将数据保存到内存中, 当用户查询数据 时, 优先从缓存容器中获取数据,而不是频繁地从数据库中查询数据,从而提高查询性能.目 前流行的缓存服务器有Mongo ...

  10. java sftp判断目录是否存在

    java sftp判断目录是否存在 public boolean isExistDir(String path,ChannelSftp sftp){ boolean isExist=false; tr ...