ROS中激光雷达数据类型传递转换及自定义点云数据类型介绍

您所在的位置:网站首页 激光雷达的强度数据有什么用途 ROS中激光雷达数据类型传递转换及自定义点云数据类型介绍

ROS中激光雷达数据类型传递转换及自定义点云数据类型介绍

2023-08-22 22:45| 来源: 网络整理| 查看: 265

目录

一、ROS中激光雷达数据类型传递转换;

二、点云数据解析;

三、自定义点云数据类型;

一、ROS中激光雷达数据类型传递转换;

     ROS中涉及激光雷达传递的消息类型有两种,一种是针对2D雷达:sensor_msgs::LaserScan;一种是针对3D雷达的即点云数据的:sensor_msgs::PointCloud2.

(1) 2D激光雷达LaserScan;

ROS中LaserScan.msg定义类型如下:

File: sensor_msgs/LaserScan.msg Raw Message Definition # Single scan from a planar laser range-finder # # If you have another ranging device with different behavior (e.g. a sonar # array), please find or create a different message, since applications # will make fairly laser-specific assumptions about this data Header header # timestamp in the header is the acquisition time of # the first ray in the scan. # # in frame frame_id, angles are measured around # the positive Z axis (counterclockwise, if Z is up) # with zero angle being forward along the x axis 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] - if your scanner # is moving, this will be used in interpolating position # of 3d points 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]. If your # device does not provide intensities, please leave # the array empty.

发布: 

#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 = 1000; double laser_frequency = 50; double ranges[num_readings]; double intensities[num_readings]; int count = 0; ros::Rate r(10.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); // 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); r.sleep(); } }

接收:

#include #include #define PI 3.1415926 void laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg) { std::vector ranges = msg->ranges; //转换到二维XY平面坐标系下; for(int i=0; i< ranges.size(); i++) { double angle = msg.angle_min + i * msg.angle_increment; double X = ranges[i] * cos(angle); double Y = ranges[i] * sin(angle); float intensity = msg.intensities[i]; std::cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3