写一个C++代码读取在ros工作环境下思岚A1激光雷达0°-180°探测的数据
时间: 2023-03-14 22:02:55 浏览: 272
C++激光雷达数据采集或读取、显示、直线拟合、角点提取、圆弧拟合、位姿解算等软件代码
5星 · 资源好评率100%
#include <stdio.h>
#include <string.h>
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>int main(int argc, char **argv)
{
ros::init(argc, argv, "laser_data_reader");
ros::NodeHandle n;
ros::Subscriber laser_sub = n.subscribe("scan", 1000, laser_callback);
ros::spin();
return 0;
}void laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
int count = msg->scan_time / msg->time_increment;
for(int i = 0; i < count; i++)
{
float degree = RAD2DEG(msg->angle_min + msg->angle_increment * i);
if(degree >= 0 && degree <=180)
{
float range = msg->ranges[i];
printf("degree=%f, range=%f \n", degree, range);
}
}
}
阅读全文