激光雷达工作原理
- 数据格式
lihongli@lhl:~/catkin_ws$ rostopic echo /scan --noarr
---
header: seq: 4663stamp: secs: 594nsecs: 481000000frame_id: "laser"
angle_min: -3.141590118408203
angle_max: 3.141590118408203
angle_increment: 0.017501894384622574
time_increment: 0.0
scan_time: 0.0
range_min: 0.23999999463558197
range_max: 6.0
ranges: "<array type: float32, length: 360>"
intensities: "<array type: float32, length: 360>"---
**
- 使用C++ 编写接受雷达数据。
**
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>void LidarCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{// Process the Lidar data herefloat fMidDist = msg->ranges[180]; // Example: get the distance at 180 degreesROS_INFO("前方 180 degrees 距离: %f", fMidDist);ROS_INFO("Received Lidar scan with %zu ranges", msg->ranges.size());// You can access the ranges, intensities, etc. from the msg
}int main(int argc, char** argv)
{setlocale(LC_ALL, "");ros::init(argc, argv, "lidar_node");ros::NodeHandle n;ros::Subscriber lidar_sub = n.subscribe("/scan", 10,&LidarCallback); ros::spin();return 0;
}