setting up your robot with tf(一)

2024-06-23 09:38
文章标签 robot tf setting

本文主要是介绍setting up your robot with tf(一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1,setting up your robot using tf     官网学习http://wiki.ros.org/tf/Tutorials

2,transform configuration

Many ROS packages require the transform tree of a robot to be published using thetf software library. At an abstract level, a transform tree defines offsets in terms of both translation and rotation between different coordinate frames. To make this more concrete, consider the example of a simple robot that has a mobile base with a single laser mounted on top of it. In referring to the robot let's define two coordinate frames: one corresponding to the center point of the base of the robot and one for the center point of the laser that is mounted on top of the base. Let's also give them names for easy reference. We'll call the coordinate frame attached to the mobile base "base_link" (for navigation, its important that this be placed at the rotational center of the robot) and we'll call the coordinate frame attached to the laser "base_laser."

许多ROS包需要机器人转换树用tf软件包来发布。在抽象层次来看,一棵转换树定义了不同的坐标系之间的转换和旋转的偏差。为了更具体,用一个例子如一个简单的机器人带有一个移动的躯干和一个简单的激光器在躯干的上面。为了更好区分,我们称这个躯干的坐标系为base_link(这个坐标系通常放在正中间),激光器的坐标系称作base_laser.

At this point, let's assume that we have some data from the laser in the form of distances from the laser's center point. In other words, we have some data in the "base_laser" coordinate frame. Now suppose we want to take this data and use it to help the mobile base avoid obstacles in the world. To do this successfully, we need a way of transforming the laser scan we've received from the "base_laser" frame to the "base_link" frame. In essence, we need to define a relationship between the "base_laser" and "base_link" coordinate frames

这样来说,让我们假设我们有一些数据来自激光器正中间的前方,也就是说,我们有一些数据在base_laser坐标系上,现在假设我们想得到这些数据并利用它来帮助躯干移动来避开障碍物,这样的话,我们需要一种方式来将我们得到的base_laser数据转换给base_link框架,因此,我们需要在base_laser和base_link坐标系之间定义一种关系。(这段话说明的是,比如我们的机器人想用激光测距来使机器人避障,当激光器得到数据之后,怎样把相对的坐标位置转换给躯干,然后使躯干移动避障,这样就需要定义激光器和躯干也就是不同的frame之间要定义一种关系)

In defining this relationship, assume we know that the laser is mounted 10cm forward and 20cm above the center point of the mobile base. This gives us a translational offset that relates the "base_link" frame to the "base_laser" frame. Specifically, we know that to get data from the "base_link" frame to the "base_laser" frame we must apply a translation of (x: 0.1m, y: 0.0m, z: 0.2m), and to get data from the "base_laser" frame to the "base_link" frame we must apply the opposite translation (x: -0.1m, y: 0.0m, z: -0.20m).

为了定义这种关系,假设我们知道激光器是在躯干的前方10cm和上方20cm,这样框架base_link和base_laser之间有一个转换偏差。如果要定义base_laser对应于base_link的数据,则需要添加一个转换关系(x:0.1......),而要定义base_link对应与base_laser的数据,只需要添加一个转换关系(x:-0.1.....)

We could choose to manage this relationship ourselves, meaning storing and applying the appropriate translations between the frames when necessary, but this becomes a real pain as the number of coordinate frames increase. Luckily, however, we don't have to do this work ourselves. Instead we'll define the relationship between "base_link" and "base_laser" once using tf and let it manage the transformation between the two coordinate frames for us. 

我们需要自己管理这种转换关系,意思是当需要的时候,我们要存储并条用合适的转换关系,但是这是一项很复杂很令人头痛的工作,尤其是当坐标系的数量增加时。幸运的是,我们不用自己做这件事了。我们只需要用tf将base_link和base_laser之间的关系定义一次,之后就让tf来帮我们管理这两个坐标系之间的转换微笑

To define and store the relationship between the "base_link" and "base_laser" frames using tf, we need to add them to a transform tree. Conceptually, each node in the transform tree corresponds to a coordinate frame and each edge corresponds to the transform that needs to be applied to move from the current node to its child. Tf uses a tree structure to guarantee that there is only a single traversal that links any two coordinate frames together, and assumes that all edges in the tree are directed from parent to child nodes

为了用tf来定义和存储base_link和base_laser框架之间的关系,我们需要将它们添加进转换树。概念上来说,转化树上的每一个节点对应一个坐标系,每一条边对应从现在的节点到它子节点之间的转换。TF利用了树形结构来定义而且是单遍历的关系来将两个坐标系连接在一起,也即假设所有的边都是从父节点到子节点。

总的来说,就是定义了一个TF转换树,而且是单遍历的树,即关系是从父节点到子节点,tf定义和存储这棵关系树后,这样框架之间的关系就很明确了,tf会帮我们调用这些关系,比如当激光器测量到距离障碍物0.3米时,由关系树知道躯干距离障碍物为0.4米,这样就能使躯干决定是否移动来躲避障碍物了微笑

3,writing code(C++)

首先要创建一个节点负责发布转换消息,然后再创建一个节点来收听通过ROS发布的转换消息并用它来转换一个点。

3.1 broadcasting a transform发布转换,发布转换base_laser-->base_link之间的转换

tf_broadcaster.cpp:

   1 #include <ros/ros.h>
   2 #include <tf/transform_broadcaster.h>
//要使用TransformBroadcaster来发布转换消息,这样就必须包括tf包里面的tranform_broadcaster.h头文件
   3 
   4 int main(int argc, char** argv){
   5   ros::init(argc, argv, "robot_tf_publisher");
   6   ros::NodeHandle n;
   7 
   8   ros::Rate r(100);
   9 
  10   tf::TransformBroadcaster broadcaster;
//创建一个TransformBroadcaster对象来发送base_link转换消息给base_laser11 
  12   while(n.ok()){
  13     broadcaster.sendTransform(
  14       tf::StampedTransform(
  15         tf::Transform(tf::Quaternion(0, 0, 0, 1), tf::Vector3(0.1, 0.0, 0.2)),
  16         ros::Time::now(),"base_link", "base_laser"));
  17     r.sleep();
//用TransformBroadcaster来发布一个转换需要五个参数:第一个为旋转转换,那个包括btQuaternion和btVector3,其中btQuaternion包括pitch,roll,yaw,而btVector3
//就对应一个转换,对应robot base的laser的偏差为x轴偏差为10cm,z轴偏差为20cm;第三个为发布一个时间戳,这里设置为now();第四个为父节点的名称,这里为base_link;第五个为子节点的
//名称,这里为base_laser18   }
  19 }
3.2 using a transform

创建完一个节点来发布base_laser-->base_link的转换消息,也就是base_laser-->base_link之间的tf转换为(0.1,0.0,0.2).

现在来创建一个节点用来使用这个转换,给base_laser框架一个值之后,使用转换来获得base_link的值。

tf_listener.cpp:

   1 #include <ros/ros.h>
   2 #include <geometry_msgs/PointStamped.h>
   3 #include <tf/transform_listener.h>
//获得TransformListener来自动订阅转换消息,也即订阅到TransformBroadcaster发布的消息
   4 
   5 void transformPoint(const tf::TransformListener& listener)
//创建一个函数,给base_laser一个点,并将它转换为base_link框架
{
   6   //we'll create a point in the base_laser frame that we'd like to transform to the base_link frame
   7   geometry_msgs::PointStamped laser_point;
//创建一个geometry_msgs::PointStamped的点,其中Stamped意思是包含一个头文件,允许我们连接一个timestamp时间戳和一个frame_id框架id,其中timestamp设为
//ros::Time(),而frame_id设为base_laser,并将它的点值设为以下那些值x:1.0,y:0.2,z:0.0;
8   laser_point.header.frame_id = "base_laser";
   9 
  10   //we'll just use the most recent transform available for our simple example
  11   laser_point.header.stamp = ros::Time();
  12 
  13   //just an arbitrary point in space
  14   laser_point.point.x = 1.0;
  15   laser_point.point.y = 0.2;
  16   laser_point.point.z = 0.0;
  17 
  18   try{
  19     geometry_msgs::PointStamped base_point;
  20     listener.transformPoint("base_link", laser_point, base_point);
  21 
  22     ROS_INFO("base_laser: (%.2f, %.2f. %.2f) -----> base_link: (%.2f, %.2f, %.2f) at time %.2f",
  23         laser_point.point.x, laser_point.point.y, laser_point.point.z,
  24         base_point.point.x, base_point.point.y, base_point.point.z, base_point.header.stamp.toSec());
  25   }
//为了将base_laser转换为base_link框架,需要使用TransformListener对象,并调用它的转换点函数transformPoint(),里面含有三个参数:想转换点的框架的名称这里为
base_link,我们从哪里转换的点这里为laser_point,转换后存储点这里为base_point
26   catch(tf::TransformException& ex){
  27     ROS_ERROR("Received an exception trying to transform a point from \"base_laser\" to \"base_link\": %s", ex.what());
  28   }
  29 }
  30 
  31 int main(int argc, char** argv){
  32   ros::init(argc, argv, "robot_tf_listener");
  33   ros::NodeHandle n;
  34 
  35   tf::TransformListener listener(ros::Duration(10));
  36 
  37   //we'll transform a point once every second每隔一秒调用一次transformPoint函数,每隔一秒转换一次
  38   ros::Timer timer = n.createTimer(ros::Duration(1.0), boost::bind(&transformPoint, boost::ref(listener)));
  39 
  40   ros::spin();
  41 
  42 }
总结: 先运行节点tf_broadcaster,在运行节点tf_listener,即先发布base_link与base_laser的关系,再通过关系来计算使用。利用的是TransformBroadcaster和TransformListener这两个对象。


























这篇关于setting up your robot with tf(一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1086790

相关文章

tf.split()函数解析

API原型(TensorFlow 1.8.0): tf.split(     value,     num_or_size_splits,     axis=0,     num=None,     name='split' ) 这个函数是用来切割张量的。输入切割的张量和参数,返回切割的结果。  value传入的就是需要切割的张量。  这个函数有两种切割的方式: 以三个维度的张量为例,比如说一

setting up your robot with tf(二)

1,using the robot state publisher on your own robot 上面一节是使用TF树结构来表示不同的框架之间的关系,且这棵TF转换树是一棵单遍历的树,表示了不同框架之间的关系,我们写了一个节点,用来定义两个框架的关系,这样下次使用就能自动调用这种关系,这样tf就帮我们做了很重要的一份工作。这一节我们学习robot state publisher。当我们的机

使用tf*idf实现对文档集合的检索

步骤: 读取三篇文档1.txt,2.txt,3.txt,里边的内容分别为“this is php”,“this is html html”,“this is java” 分词,并统计词频tf 计算文档频率df 计算每篇文档的特征向量 计算搜索词与文档的夹角余弦值 <?php$_txts = array('1.txt','2.txt','3.txt');$_len = cou

tf.squeeze/tf.expand_dims

在git上的FM开源代码中看到了这样子的用法 https://github.com/Aifcce/FM-FFM/blob/master/model/FM.py batch_weights = tf.squeeze(batch_weights, axis=2) df_v = tf.expand_dims(df_v, axis=2) tf.squeeze是降维,把维度为1的去掉,我的理

SparkML中三种文本特征提取算法(TF-IDF/Word2Vec/CountVectorizer)

在SparkML中关于特征的算法可分为Extractors(特征提取)、Transformers(特征转换)、Selectors(特征选择)三部分: Feature Extractors TF-IDFWord2VecCountVectorizer Feature Transformers TokenizerStopWordsRemover n n-gramBinarizerP

tf.train.batch和tf.train.shuffle_batch的理解

capacity是队列的长度 min_after_dequeue是出队后,队列至少剩下min_after_dequeue个数据 假设现在有个test.tfrecord文件,里面按从小到大顺序存放整数0~100 1. tf.train.batch是按顺序读取数据,队列中的数据始终是一个有序的队列, 比如队列的capacity=20,开始队列内容为0,1,..,19=>读取10条记录后,队列剩下10,

idea设置maven配置文件setting.xml的位置

---------------------  作者:fengqing5578  来源:CSDN  原文:https://blog.csdn.net/fengqing5578/article/details/82854495  版权声明:本文为博主原创文章,转载请附上博文链接!

Contact-Rich Robot ManipulationTask:grinding and Peg-in-Hole Assembly

Contact-Rich Robot Manipulation Task涵盖了多种需要机器人与环境或物体进行密切接触的复杂操作。 1. Grinding(研磨) 任务描述:研磨是制造业中常见的加工过程,涉及使用研磨工具去除材料表面的一层或多层,以达到预定的形状、尺寸或表面光洁度。在机器人研磨任务中,机器人需要精确控制其末端执行器(如研磨头)的运动,以确保在工件上施加正确的力和速度。挑战: 精确

【NLP项目-01】手把手教你基于TF-IDF提取向量+贝叶斯或者随机森林进行文本分类

【NLP项目-01】手把手教你基于TF-IDF提取向量+贝叶斯或者随机森林进行文本分类   本次修炼方法请往下查看 🌈 欢迎莅临我的个人主页 👈这里是我工作、学习、实践 IT领域、真诚分享 踩坑集合,智慧小天地! 🎇 相关内容文档获取 微信公众号 🎇 相关内容视频讲解 B站 🎓 博主简介:AI算法驯化师,混迹多个大厂搜索、推荐、广告、数据分析、数据挖掘岗位 个人申请专利40+,

Robot Framework完整流程学习系列一

一.环境搭建 网上有很多的教程,这里就不多讲了 二.RIDE的界面认识 这里只介绍几个重要常用的功能,其他相信自己都能理解 1.Search Keywords(F5): 搜索关键字 2.ContentAssistance:内容助手       3.ViewRIDELog:查看RIDE日志,使用过程