Ros 消息结构1

1ROS的消息头信息

    

#Standard metadata for higher-level flow data types
#sequence ID: consecutively increasing ID 
uint32 seq#Two-integer timestamp that is expressed as:
# * stamp.secs: seconds (stamp_secs) since epoch
# * stamp.nsecs: nanoseconds since stamp_secs
# time-handling sugar is provided by the client library
time stamp#Frame this data is associated with
# 0: no frame
# 1: global frame
string frame_id

       以上是标准头信息的主要部分。seq是消息的顺序标识,不需要手动设置,发布节点在发布消息时,会自动累加。stamp 是消息中与数据相关联的时间戳,例如激光数据中,时间戳对应激光数据的采集时间点。frame_id 是消息中与数据相关联的参考系id,例如在在激光数据中,frame_id对应激光数据采集的参考系


2.1、激光消息的结构

      针对激光雷达,ROSsensor_msgs 包中定义了专用了数据结构来存储激光消息的相关信息,成为LaserScanLaserScan消息的格式化定义,为虚拟的激光雷达数据采集提供了方便,在我们讨论如何使用他之前,来看看该消息的结构是什么样的:

#
# Laser scans angles are measured counter clockwise, with 0 facing forward
# (along the x-axis) of the device frame
#Header header
float32 angle_min        # start angle of the scan [rad]
float32 angle_max        # end angle of the scan [rad]
float32 angle_increment  # angular distance between measurements [rad]
float32 time_increment   # time between measurements [seconds]
float32 scan_time        # time between scans [seconds]
float32 range_min        # minimum range value [m]
float32 range_max        # maximum range value [m]
float32[] ranges         # range data [m] (Note: values < range_min or > range_max should be discarded)
float32[] intensities    # intensity data [device-specific units]

      备注中已经详细介绍了每个参数的意义。

2.2、通过代码发布LaserScan消息

    使用ROS发布LaserScan格式的激光消息非常简洁,下边是一个简单的例程:

#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>int main(int argc, char** argv){ros::init(argc, argv, "laser_scan_publisher");ros::NodeHandle n;ros::Publisher scan_pub = n.advertise<sensor_msgs::LaserScan>("scan", 50);unsigned int num_readings = 100;double laser_frequency = 40;double ranges[num_readings];double intensities[num_readings];int count = 0;ros::Rate r(1.0);while(n.ok()){//generate some fake data for our laser scanfor(unsigned int i = 0; i < num_readings; ++i){ranges[i] = count;intensities[i] = 100 + count;}ros::Time scan_time = ros::Time::now();//populate the LaserScan messagesensor_msgs::LaserScan scan;scan.header.stamp = scan_time;scan.header.frame_id = "laser_frame";scan.angle_min = -1.57;scan.angle_max = 1.57;scan.angle_increment = 3.14 / num_readings;scan.time_increment = (1 / laser_frequency) / (num_readings);scan.range_min = 0.0;scan.range_max = 100.0;scan.ranges.resize(num_readings);scan.intensities.resize(num_readings);for(unsigned int i = 0; i < num_readings; ++i){scan.ranges[i] = ranges[i];scan.intensities[i] = intensities[i];}scan_pub.publish(scan);++count;r.sleep();}
}

    我们将代码分解以便于分析:

#include <sensor_msgs/LaserScan.h>

    首先我们需要先包含Laserscan的数据结构。

ros::Publisher scan_pub = n.advertise<sensor_msgs::LaserScan>("scan", 50);

    创建一个发布者,以便于后边发布针对scan主题的Laserscan消息。

  unsigned int num_readings = 100;double laser_frequency = 40;double ranges[num_readings];double intensities[num_readings];int count = 0;ros::Rate r(1.0);while(n.ok()){//generate some fake data for our laser scanfor(unsigned int i = 0; i < num_readings; ++i){ranges[i] = count;intensities[i] = 100 + count;}ros::Time scan_time = ros::Time::now();

    这里的例程中我们虚拟一些激光雷达的数据,如果使用真是的激光雷达,这部分数据需要从驱动中获取。

    //populate the LaserScan messagesensor_msgs::LaserScan scan;scan.header.stamp = scan_time;scan.header.frame_id = "laser_frame";scan.angle_min = -1.57;scan.angle_max = 1.57;scan.angle_increment = 3.14 / num_readings;scan.time_increment = (1 / laser_frequency) / (num_readings);scan.range_min = 0.0;scan.range_max = 100.0;scan.ranges.resize(num_readings);scan.intensities.resize(num_readings);for(unsigned int i = 0; i < num_readings; ++i){scan.ranges[i] = ranges[i];scan.intensities[i] = intensities[i];}

    创建scan_msgs::LaserScan数据类型的变量scan,把我们之前伪造的数据填入格式化的消息结构中。

scan_pub.publish(scan);

    数据填充完毕后,通过前边定义的发布者,将数据发布。



3.1、点云消息的结构

      

#This message holds a collection of 3d points, plus optional additional information about each point.#Each Point32 should be interpreted as a 3d point in the frame given in the headerHeader headergeometry_msgs/Point32[] points  #Array of 3d pointsChannelFloat32[] channels       #Each channel should have the same number of elements as points array, and the data in each channel should correspond 1:1 with each point

      如上所示,点云消息的结构支持存储三维环境的点阵列,而且channels参数中,可以设置这些点云相关的数据,例如可以设置一个强度通道,存储每个点的数据强度,还可以设置一个系数通道,存储每个点的反射系数,等等。

3.2、通过代码发布点云数据

     ROS发布点云数据同样简洁:

#include <ros/ros.h>
#include <sensor_msgs/PointCloud.h>int main(int argc, char** argv){ros::init(argc, argv, "point_cloud_publisher");ros::NodeHandle n;ros::Publisher cloud_pub = n.advertise<sensor_msgs::PointCloud>("cloud", 50);unsigned int num_points = 100;int count = 0;ros::Rate r(1.0);while(n.ok()){sensor_msgs::PointCloud cloud;cloud.header.stamp = ros::Time::now();cloud.header.frame_id = "sensor_frame";cloud.points.resize(num_points);//we'll also add an intensity channel to the cloudcloud.channels.resize(1);cloud.channels[0].name = "intensities";cloud.channels[0].values.resize(num_points);//generate some fake data for our point cloudfor(unsigned int i = 0; i < num_points; ++i){cloud.points[i].x = 1 + count;cloud.points[i].y = 2 + count;cloud.points[i].z = 3 + count;cloud.channels[0].values[i] = 100 + count;}cloud_pub.publish(cloud);++count;r.sleep();}
}

     分解代码来分析:

#include <sensor_msgs/PointCloud.h>

     首先也是要包含sensor_msgs/PointCloud消息结构。

ros::Publisher cloud_pub = n.advertise<sensor_msgs::PointCloud>("cloud", 50);

     定义一个发布点云消息的发布者。

sensor_msgs::PointCloud cloud;
cloud.header.stamp = ros::Time::now();
cloud.header.frame_id = "sensor_frame";

     为点云消息填充头信息,包括时间戳和相关的参考系id

cloud.points.resize(num_points);

     设置存储点云数据的空间大小。

 //we'll also add an intensity channel to the cloud
cloud.channels.resize(1);
cloud.channels[0].name = "intensities";
cloud.channels[0].values.resize(num_points);

     设置一个名为“intensity“的强度通道,并且设置存储每个点强度信息的空间大小。

 //generate some fake data for our point cloudfor(unsigned int i = 0; i < num_points; ++i){cloud.points[i].x = 1 + count;cloud.points[i].y = 2 + count;cloud.points[i].z = 3 + count;cloud.channels[0].values[i] = 100 + count;}

     将我们伪造的数据填充到点云消息结构当中。

cloud_pub.publish(cloud);

      最后,发布点云数据。



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440168.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【HDU - 5475】An easy problem(线段树,思维)

题干&#xff1a; One day, a useless calculator was being built by Kuros. Lets assume that number X is showed on the screen of calculator. At first, X 1. This calculator only supports two types of operation. 1. multiply X with a number. 2. divide X with…

图解算法学习笔记(六):广度优先搜索

目录 1&#xff09;图简介 2&#xff09;图是什么 3&#xff09;广度优先搜索 4&#xff09;实现图 5&#xff09;实现算法 6&#xff09;小结 本章内容; 学习使用新的数据结构图来建立网络模型&#xff1b; 学习广度优先搜索&#xff1b; 学习有向图和无向图…

图解算法学习笔记(七):狄克斯特拉算法

目录 1&#xff09;使用狄克斯特拉算法 2&#xff09;术语 3&#xff09;实现 4&#xff09;小结 本章内容; 介绍加权图&#xff0c;提高或降低某些边的权重&#xff1b; 介绍狄克斯特拉算法&#xff0c;找出加权图中前往X的最短路径&#xff1b; 介绍图中的环…

【HDU - 5477】A Sweet Journey(思维,水题)

题干&#xff1a; Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the f…

[转载]Bluetooth协议栈学习之SDP

原文地址&#xff1a;Bluetooth协议栈学习之SDP作者&#xff1a;BigSam78作者&#xff1a; Sam &#xff08;甄峰&#xff09; sam_codehotmail.com SDP(service discovery protocol&#xff1a;服务发现协议)提供了一个方法&#xff0c;让应用程序检测哪些服务是可用的并探测这…

图解算法学习笔记(八):贪婪算法

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;集合覆盖问题 &#xff08;3&#xff09;NP完全问题 &#xff08;4&#xff09;小结 本章内容&#xff1a; 学习如何处理没有快速算法的问题&#xff08;NP完全问题&#xff09;。学习近似算法&#xff…

【CodeForces - 1152C 】Neko does Maths(数学数论,lcm,gcd性质)

题干&#xff1a; 给出a,b<1e9&#xff0c;你要找到最小的k使得lcm(ak,bk)尽可能小&#xff0c;如果有多个k给出同样的最小公倍数&#xff0c;输出最小的一个k。 解题报告&#xff1a; 因为题目中k太多了&#xff0c;先化简一下公式&#xff0c;假设a>b &#xff0c;则…

vs visual studio 2015安装后的几个问题

前言 最近在win7下重新安装了visual studio 2015&#xff0c;没有安装在默认路径下&#xff0c;编译时出现不少问题&#xff0c;整理如下 1.Failed to locate: "CL.exe". The system cannot find the file specified. TRACKER : error TRK0005: Failed to locate: “…

图解算法学习笔记(九):动态规划

目录 &#xff08;1&#xff09;背包问题 &#xff08;2&#xff09;最长公共子串 &#xff08;3&#xff09;小结 本章内容&#xff1a; 学习动态规划&#xff0c;它将问题分成小问题&#xff0c;并先着手解决这些小问题。学习如何设计问题的动态规划解决方案。 &#xff…

Java(win10安装jdk,第一个hello world)

Java 第一步 &#xff1a;安装jdk 推荐默认安装。&#xff08;安装到C盘&#xff09;第二步 &#xff1a;配置jdk环境 JAVA_HOME C:\Program Files\Java\jdk1.8.0_191 JDK的安装路径 Path&#xff1a; C:\Program Files\Java\jdk1.8.0_191\bin JDK下bin目录的路径 &#xf…

【POJ - 3177】Redundant Paths(边双连通分量,去重边)

题干&#xff1a; In order to get from one of the F (1 < F < 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being f…

#pragma 详解

#pragma 求助编辑 pragma - 必应词典美[prɡmə]英[prɡmə]n.〔计〕杂注网络编译指示&#xff1b;显示编译指示&#xff1b;特殊指令 百科名片 在所有的预处理指令中&#xff0c;#Pragma 指令可能是最复杂的了&#xff0c;它的作用是设定编译器的状态或者是指示编译器完成一些…

1.绪论

目录 &#xff08;1&#xff09;C语言传值与传地址变量 &#xff08;2&#xff09;算法效率的度量 &#xff08;3&#xff09;基本操作 &#xff08;4&#xff09;主函数 主要由实现基本操作和算法的程序构成。这些程序有6类&#xff1a; 数据存储结构&#xff0c;文件名第…

Java 新手习题()

循环 1.&#xff08;for 循环&#xff09;计算123…100 的和 package com.fxm.day03.test; public class day03test1{public static void main(String[] args){int sum 0;for(int i 1; i < 101; i){sum i;}System.out.println("1到100的和&#xff1a;"sum);…

(ECC)椭圆曲线加密算法原理和C++实现源码

目录 &#xff08;1&#xff09;ECC加密原理&#xff1a; &#xff08;2&#xff09;编译生成LibTommath静态库 &#xff08;3&#xff09;ECC源码 今天介绍一下利用LibTommath数学库实现椭圆曲线加密算法的原理和源码。 &#xff08;1&#xff09;ECC加密原理&#xff1a;…

【POJ - 2553】The Bottom of a Graph(tarjan强连通分量缩点,模板题)

题干&#xff1a; We will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called vertices (or nodes). Let E be a subset of the Cartesian product VV, its elements being called edges. Then G(…

c语言3种链接属性: 外部(external), 内部(internal),无设置(none)

c语言中&#xff0c;多个文件组合的时候&#xff0c;有可能标示名相同&#xff0c;那么这个时候编译器如何判别的呢&#xff1f; c语言中有3种链接属性: 外部&#xff08;external&#xff1a;可以被其他文件访问到&#xff09;, 内部(internal&#xff1a;无法被其他文件访问到…

java 数组习题

2.写一个函数&#xff0c;返回一个整数数组的平均值 package com.fxm.day05.test; public class Day05test{public static void main(String[] args){int[] a1 {2,9,5,7,4};int n average(a1);System.out.println(n);}public static int average(int[] a){int sum 0;for(in…

机器学习笔记(1):Introduction

目录 1&#xff09;welcome 2&#xff09;What is Machine Learning 3&#xff09;Supervised Learning 4&#xff09;Unsupervised Learning 1&#xff09;welcome 第一个视频主要介绍了机器学习目前的案例&#xff0c;主要有&#xff1a;数据库挖掘、医疗记录、生物工程…

【POJ - 3352】Road Construction(Tarjan,边双连通分量)

题干&#xff1a; Its almost summer time, and that means that its almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like to repair and upgrade the various roads…