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;

  • UC3846控制芯片工作原理控制图 逆变焊机原理与用途
  • 数字万用表电阻档测试二极管正反向没有阻值(使用万用表测量二极管的正向电阻,为什么各档)
  • 学单片机需要学数电模电吗(学单片机要先学数电模电吗)
  • 电工怎么选择适合自己用的万用表(电工初学者买什么样的万用表好)
  • 单片机需要同时运行多个任务怎么办(单片机怎么同时执行多个任务)
  • 电机保护的方案取决于负载的机械特性
  • 绝缘电阻表正负搭接不复零位是怎么回事
  • 短路怎么用万用表查