写一个C++代码读取在ros工作中思岚A1激光雷达部分角度测得的数据
时间: 2023-03-14 17:02:55 浏览: 303
#include <stdio.h>
#include <ros/ros.h>int main(int argc, char **argv){
ros::init(argc, argv, "read_A1_data");
ros::NodeHandle nh;
// 读取A1激光雷达角度数据
ros::Subscriber sub = nh.subscribe("/scan", 1000, readA1Data);
ros::spin();
return 0;
}void readA1Data(const sensor_msgs::LaserScan::ConstPtr& scan){
int count = scan->scan_time / scan->time_increment;
for(int i = 0; i < count; i++){
float angle = scan->angle_min + i*scan->angle_increment;
float range = scan->ranges[i];
printf("角度 %f, 距离 %f \n", angle, range);
}
}
阅读全文