ROS Learning-019 learning_tf-03(编程) 添加额外的坐标系 (Python版)
ROS Indigo learning_tf-03 添加额外的坐标系 (Python版)
我使用的虚拟机软件:VMware Workstation 11
使用的Ubuntu系统:Ubuntu 14.04.4 LTS
ROS 版本:ROS Indigo
前言
这一节要做的事情:添加额外的坐标系。为什么要添加额外的坐标系:
对于许多任务很容易想到内嵌一个局部的坐标系。例如,将激光扫描仪的中心作为坐标系原点的激光扫描的结果更容易被理解。 TF 允许您为每个传感器、连杆等系统定义局部坐标系。
还是在 learning_tf 软件包中的 nodes 文件夹中创建一个 fixed_tf_broadcaster.py 文件:
$ roscd learning_tf
$ gedit nodes/fixed_tf_broadcaster.py
并将下面的代码添加进去:
#!/usr/bin/env python
import roslib
roslib.load_manifest('learning_tf')
import rospy
import tf
import math
if __name__ == '__main__':
rospy.init_node('my_tf_broadcaster')
br = tf.TransformBroadcaster()
rate = rospy.Rate(10.0)
while not rospy.is_shutdown():
t = rospy.Time.now().to_sec() * math.pi
br.sendTransform((2.0 * math.sin(t), 2.0 * math.cos(t), 0.0),
(0.0, 0.0, 0.0, 1.0),
rospy.Time.now(),
"carrot1",
"turtle1")
rate.sleep()
代码讲解:
最后一步,给这个 fixed_tf_broadcaster.py 文件加上可执行权限:
$ chmod +x fixed_tf_broadcaster.py
和前几节一样,上面的程序是一个节点,我们需要编写一个启动脚本文件,将几个节点同时运行,才能看到效果:
$ roscd learning_tf/launch
$ gedit start_demo3.launch
所以,在 start_demo2.launch 文件的 <launch> 便签里面添加下面这句,另存为:start_demo3.launch :
<node pkg="learning_tf" type="fixed_tf_broadcaster.py" name="broadcaster_fixed" />
完整的 start_demo3.launch :
<launch>
<!-- Turtlesim Node -->
<node pkg="turtlesim" type="turtlesim_node" name="sim" />
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen" />
<node name="turtle1_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
<param name="turtle" type="string" value="turtle1" />
</node>
<node name="turtle2_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
<param name="turtle" type="string" value="turtle2" />
</node>
<node pkg="learning_tf" type="turtle_tf_listener.py" name="listener" />
<node pkg="learning_tf" type="fixed_tf_broadcaster.py" name="broadcaster_fixed" />
</launch>
运行 start_demo3.launch 启动脚本文件:
$ roslaunch learning_tf start_demo3.launch
程序运行的效果,和上一节的是一样的。这是为什么?
因为我们没有启动名字叫 ” carrot1 ” 的节点。我们现在可以使用 rosnode list 将当前运行的节点都列出来:
$ rosnode list
/broadcaster_fixed
/listener
/rosout
/sim
/teleop
/turtle1_tf_broadcaster
/turtle2_tf_broadcaster
里面没有 “ carrot1 ” 这个节点。但是,我们将当前的 tf 树型关系图: ( tf 关系树) (新的命令)
$ rosrun rqt_tf_tree rqt_tf_tree
我们现在可以使用 rosrun tf tf_echo /turtle1 /carrot1 命令来将 carrot1 的 tf 信息打印到终端上:
$ rosrun tf tf_echo /turtle1 /carrot1
在之前的博客里面,我们讲过:
tf_echo关键字 : 打印出 源坐标系 和 目标坐标系 之间的特定转换信息。$ rosrun tf tf_echo [源坐标系(父类)] [目标坐标系(子类)]
输出的信息:
这个结果是正确的,因为‘carrot1’ 绕着 ‘turtle1‘做半径为2的圆周运动。(上面打印出来的 ’ carrot1 ’ 的tf信息 是以 ’ turtle1 ’ 为坐标原点 做参考的。)
我们上面编程的fixed_tf_broadcaster.py程序它做了什么你知道吗?
它只是将 carrot1 的 tf 信息广播了出来,并没有给 /carrot1/cmd_vel 这个话题发布消息,并且我们也没有再生( spawn )一个 ” carrot1 ” 小海龟。所以,结果就是现在这个样子。
By The Way :
上面出现的 tf 关系树,下面我做以解释:
Tf 建立了一个坐标系的关系树型图。一个坐标系节点只能有一个父类,可以有多个子类。
现在你要添加一个坐标系( carrot1 )到这个树型关系图中, 就必须选择一个已有的坐标系(turtle1、turtle2、world)作为父类,而这个新的坐标系( carrot1 )就是子类。 如图:
总结:
其实这一节想要讲的内容已经讲完了:就是如何新建一个 tf 坐标系。
ok , 这一节,就已经介绍完了。因为这一节,我们还有没有看到小海龟窗口中小海龟什么新的动作。
所以,下一节我们在写一个新的监听坐标系变化的程序,希望看到的运行效果是: turtle2 海龟围绕着 ’ turtle1 ’ 海龟转圈。(因为:’ turtle2 ’ 小海龟设置在 ’ carrot1 ’ 这个坐标系节点上,而 carrot 坐标系节点围绕这个 turtle1 坐标系节点做画圆的变化。)
ROS Learning-019 learning_tf-03(编程) 添加额外的坐标系 (Python版)的更多相关文章
- 【Spark机器学习速成宝典】模型篇03线性回归【LR】(Python版)
目录 线性回归原理 线性回归代码(Spark Python) 线性回归原理 详见博文:http://www.cnblogs.com/itmorn/p/7873083.html 返回目录 线性回归代码( ...
- 【Spark机器学习速成宝典】基础篇03数据读取与保存(Python版)
目录 保存为文本文件:saveAsTextFile 保存为json:saveAsTextFile 保存为SequenceFile:saveAsSequenceFile 读取hive 保存为文本文件:s ...
- ROS Learning-020 learning_tf-04(编程)让turtle2 海龟跟随turtle1海龟,并绕着 turtle1海龟转圈 (Python版)
ROS Indigo learning_tf-04 (编程)让 turtle2 海龟跟随 turtle1 海龟,并绕着 turtle1 海龟转圈 (Python版) 我使用的虚拟机软件:VMware ...
- ROS Learning-015 learning_tf(编程) 编写一个监听器程序 (Python版)
ROS Indigo learning_tf-02 编写一个 监听器 程序 (Python版) 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 1 ...
- ROS Learning-014 learning_tf(编程) 坐标系变换(tf)广播员 (Python版)
ROS Indigo learning_tf-01 坐标系变换(tf)广播员 (Python版) 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu ...
- ROS Learning-022 learning_tf-06(编程) 现在与过去中穿梭 (Python版) --- waitForTransformFull() 函数
ROS Indigo learning_tf-06 现在与过去中穿梭 (Python版) - waitForTransformFull() 函数 我使用的虚拟机软件:VMware Workstatio ...
- ROS Learning-021 learning_tf-05(编程) now() 和 Time(0) 的区别 (Python版)
ROS Indigo learning_tf-05 now() 和 Time(0)的区别 (Python版) - waitForTransform() 函数 我使用的虚拟机软件:VMware Work ...
- ROS Learning-011 beginner_Tutorials (编程) 编写 ROS 话题版的 Hello World 程序(Python版)
ROS Indigo beginner_Tutorials-10 编写 ROS 话题版的 Hello World 程序(Python版) 我使用的虚拟机软件:VMware Workstation 11 ...
- Bootstrap 表单和图片 (内联表单,表单合组,水平排列,复选框和单选框,下拉列表,校验状态,添加额外的图标,控制尺寸,图片)
一.表单 基本格式 注:只有正确设置了输入框的 type 类型,才能被赋予正确的样式. 支持的输入框控件 包括:text.password.datetime.datetime-local.date.m ...
随机推荐
- c++primer 第五章编程练习答案
5.9.1 #include<iostream> int main() { using namespace std; ; cout << "input first i ...
- Python内置函数-enumerate
enumerate 函数用于遍历序列中的元素以及它们的下标:(返回index,value) >>> for i,j in enumerate(('a','b','c')): prin ...
- BEC translation exercise 1
U.S. oil drillers have made major efficiency improvements with a speed that has repeatedly surprised ...
- boost开发指南
C++确实很复杂,神一样的0x不知道能否使C++变得纯粹和干爽? boost很复杂,感觉某些地方有过度设计和太过于就事论事的嫌疑,对实际开发工作的考虑太过于理想化.学习boost本身就是一个复杂度,有 ...
- Unity项目UI图片压缩格式(UGUI)
http://blog.csdn.net/bobodan123/article/details/70316538 UI制作时候使用的是Ps 8位 RGB通道的色彩. 但导出的是16位RGBA色彩的图片 ...
- 第五篇 Nginx的简单配置
先安装: sudo apt-get install nginx php5-fpm 我是在新安装的Ubuntu13上测试通过的,真的只安装这两个东西就够了. 然后编辑配置文件. sudo gedit / ...
- why latches are considered bad?
A "latch" is different from a "Flip-Flop" in that a FF only changes its output i ...
- Fork/Join框架介绍
转http://www.infoq.com/cn/articles/fork-join-introduction/ 1. 什么是Fork/Join框架 Fork/Join框架是Java7提供了的一个用 ...
- vector向量容器元素排序与查找
1.利用标准库函数sort()对vector进行排序 参考源码: #include <algorithm> #include <vector> vector<int> ...
- 版本管理 word 文档比较
1.因为公司还在用SVN, 2.而且 还在用word 写文档, 3.而且 commit log 基本不写, 所以导致,想了解word文档 改动, 很浪费时间!!!! 所以想 快速了解word 改动, ...