您的位置 首页 嵌入式

怎么运用代码发布导航需求的传感器信息

如何使用代码发布导航需要的传感器信息-在导航过程中,传感器的信息至关重要,这些传感器可以是激光雷达、摄像机、声纳、红外线、碰撞开关,但是归根结底,导航功能包要求机器人必须发布sensor_msgs/LaserScan或sensor_msgs/PointCloud格式的传感器信息,本篇将详细介绍如何使用代码发布所需要的消息。 1、ROS的消息头信息 无论是 sensor_msgs/LaserScan,还是sensor_msgs/PointCloud ,都和ROS中tf帧信息等时间相关的消息一样,带标准格式的头信息。 #Standard metadata for higher-level flow data types #sequence ID: consecuti

在导航过程中,传感器的信息至关重要,这些传感器可所以激光雷达、摄像机、声纳、红外线、磕碰开关,可是归根到底,导航功用包要求机器人有必要发布sensor_msgs/LaserScan或sensor_msgs/PointCloud格局的传感器信息,本篇将具体介绍怎么运用代码发布所需求的音讯。

发布导航需求的传感器信息

1、ROS的音讯头信息
无论是 sensor_msgs/LaserScan,仍是sensor_msgs/PointCloud ,都和ROS中tf帧信息等时刻相关的音讯相同,带规范格局的头信息。
#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、怎么发布激光扫描音讯
2.1、激光音讯的结构

针对激光雷达,ROS在sensor_msgs 包中界说了专用了数据结构来存储激光音讯的相关信息,成为LaserScan。LaserScan音讯的格局化界说,为虚拟的激光雷达数据收集供给了便利,在咱们评论怎么运用他之前,来看看该音讯的结构是什么样的:
#
# 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
#include

int main(int argc, char** argv){
ros::init(argc, argv, “laser_scan_publisher”);

ros::NodeHandle n;
ros::Publisher scan_pub = n.advertise(“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 scan
for(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 message
sensor_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

首要咱们需求先包含Laserscan的数据结构。
ros::Publisher scan_pub = n.advertise(“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 scan
for(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 message
sensor_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、怎么发布点云数据
3.1、点云音讯的结构
为存储和发布点云音讯,ROS界说了sensor_msgs/PointCloud音讯结构:

#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 header

Header header

geometry_msgs/Point32[] points #Array of 3d points

ChannelFloat32[] 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
#include

int main(int argc, char** argv){
ros::init(argc, argv, “point_cloud_publisher”);

ros::NodeHandle n;
ros::Publisher cloud_pub = n.advertise(“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 cloud
cloud.channels.resize(1);
cloud.channels[0].name = “intensities”;
cloud.channels[0].values.resize(num_points);

//generate some fake data for our point cloud
for(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音讯结构。
ros::Publisher cloud_pub = n.advertise(“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 cloud
for(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);

最终,发布点云数据。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/331321.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部