参数定义
# 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. 测量强度集
创建激光雷达消息包节点
# Step1:创建工作目录,添加依赖项
cd catkin_ws/src
catkin_create_pkg lidar_pkg roscpp rospy sensor_msgs
# Step2:创建lidar_node.cpp
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
void LidarCallBack(const sensor_msgs::LaserScan msg)
{
float fMidDist = msg.ranges[180];
ROS_INFO("Distance is %f", fMidDist);
}
int main(int argc, char *argv[])
{
ros::init(argc, argv, "lidar_node");
ros::NodeHandle n;
ros::Subscriber lidar_sub = n.subscribe("/scan", 10, &LidarCallBack);
ros::spin();
return 0;
}
# Step3:在CMakeLists.txt文件中,添加如下
add_executable(lidar_node src/lidar_node.cpp)
target_link_libraries(lidar_node
${catkin_LIBRARIES}
)
# Step4:在catkin_ws文件下,编译运行
catkin_make
# Step5:运行Gazebo
roslaunch wpr_simulation wpb_simple.launch
# Step6:运行lidar_node节点
rosrun lidar_pkg lidar_node