博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ROS 激光数据 点云数据的发送以及 接受
阅读量:5901 次
发布时间:2019-06-19

本文共 3443 字,大约阅读时间需要 11 分钟。

1.The LaserScan Message

   、ROS 中提供了一种很特殊的  Message type 在sensor-MSG  包当中,他是LaserScan ,他使得编码已获得的信息变得极为方便,首先看一下信息的类型。

A:激光扫描的角度是被逆时针测量的

1 Header header 2 float32 angle_min        # start angle of the scan [rad] 3 float32 angle_max        # end angle of the scan [rad] 4 float32 angle_increment  # angular distance between measurements [rad] 5 float32 time_increment   # time between measurements [seconds] 6 float32 scan_time        # time between scans [seconds] 7 float32 range_min        # minimum range value [m] 8 float32 range_max        # maximum range value [m] 9 float32[] ranges         # range data [m] (Note: values < range_min or > range_max should be discarded)10 float32[] intensities    # intensity data [device-specific units]

2. Writing Code to Publish a LaserScan Message

1 #include 
2 #include
3 4 int main(int argc, char** argv){ 5 ros::init(argc, argv, "laser_scan_publisher"); 6 7 ros::NodeHandle n; 8 ros::Publisher scan_pub = n.advertise
("scan", 50); #这是要传递的信息。 9 10 unsigned int num_readings = 100;11 double laser_frequency = 40;12 double ranges[num_readings];13 double intensities[num_readings]; # 准备创建虚拟的激光信息,这分别是平率,不太懂。。。14 15 int count = 0;16 ros::Rate r(1.0); #发送数据的速率17 while(n.ok()){18 //generate some fake data for our laser scan19 for(unsigned int i = 0; i < num_readings; ++i){20 ranges[i] = count;21 intensities[i] = 100 + count;22 }23 ros::Time scan_time = ros::Time::now(); #每隔一秒产生一个虚假的数据24 25 //populate the LaserScan message26 sensor_msgs::LaserScan scan;27 scan.header.stamp = scan_time;28 scan.header.frame_id = "laser_frame";29 scan.angle_min = -1.57;30 scan.angle_max = 1.57;31 scan.angle_increment = 3.14 / num_readings;32 scan.time_increment = (1 / laser_frequency) / (num_readings);33 scan.range_min = 0.0;34 scan.range_max = 100.0; #这些是消息内容。与前一节交相辉映35 36 scan.ranges.resize(num_readings);37 scan.intensities.resize(num_readings);38 for(unsigned int i = 0; i < num_readings; ++i){39 scan.ranges[i] = ranges[i];40 scan.intensities[i] = intensities[i];41 }42 43 scan_pub.publish(scan);44 ++count;45 r.sleep();46 }47 }

3. Publishing PointCloud Message

1 #include 
2 #include
3 4 int main(int argc, char** argv){ 5 ros::init(argc, argv, "point_cloud_publisher"); 6 7 ros::NodeHandle n; 8 ros::Publisher cloud_pub = n.advertise
("cloud", 50); 9 10 unsigned int num_points = 100;11 12 int count = 0;13 ros::Rate r(1.0);14 while(n.ok()){15 sensor_msgs::PointCloud cloud;16 cloud.header.stamp = ros::Time::now();17 cloud.header.frame_id = "sensor_frame";18 19 cloud.points.resize(num_points);20 21 //we'll also add an intensity channel to the cloud22 cloud.channels.resize(1);23 cloud.channels[0].name = "intensities";24 cloud.channels[0].values.resize(num_points);25 26 //generate some fake data for our point cloud27 for(unsigned int i = 0; i < num_points; ++i){28 cloud.points[i].x = 1 + count;29 cloud.points[i].y = 2 + count;30 cloud.points[i].z = 3 + count;31 cloud.channels[0].values[i] = 100 + count;32 }33 34 cloud_pub.publish(cloud);35 ++count;36 r.sleep();37 }38 }

 

转载于:https://www.cnblogs.com/xialuobo/p/6099305.html

你可能感兴趣的文章
RadioButton布局图片+文字 实现tabhost效果
查看>>
access中设置不等于
查看>>
hdu 1221 Rectangle and Circle
查看>>
Android 四大组件之四(ContentProvider)
查看>>
Android 四大组件之一(Activity)
查看>>
扫描(一)
查看>>
PIE SDK矢量数据的读取
查看>>
两种方式分别改变alertdialog的宽和高
查看>>
TextView-setCompondDrawables用法
查看>>
Centos7安装rabbitmq server 3.6.0
查看>>
关于eclipse的ADT(插件)对xml的android:text属性检查修改
查看>>
iostat命令学习
查看>>
SQL 三种分页方式
查看>>
查看linux是ubuntu还是centos
查看>>
html video的url更新,自动清缓存
查看>>
IOS Xib使用——为控制器添加Xib文件
查看>>
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤
查看>>
【11】ajax请求后台接口数据与返回值处理js写法
查看>>
Python菜鸟之路:Jquery Ajax的使用
查看>>
LeetCode算法题-Maximum Depth of Binary Tree
查看>>