LiDAR 服务接口
获取 LiDAR 数据
简介
LiDAR 服务接口用于订阅 LiDAR 数据话题livox/lidar
。该 topic 使用sensor_msgs/msg/PointCloud2
消息类型,包含机器人固态激光雷达所收集的点云数据。
Topic 名称 | Topic类型 | 角色 |
---|---|---|
livox/lidar | sensor_msgs/msg/PointCloud2 | 订阅方 |
消息结构
bash
std_msgs/Header header # 消息头,包含时间戳和坐标系信息
uint32 height # 点云的高度(通常为 1,表示无序点云)
uint32 width # 点云的宽度(点数)
sensor_msgs/PointField[] fields # 描述点云中每个点的字段(如 x, y, z, intensity 等)
bool is_bigendian # 数据字节序(通常为 false,表示小端序)
uint32 point_step # 每个点的字节数
uint32 row_step # 每行的字节数
uint8[] data # 点云数据(二进制格式)
bool is_dense # 点云是否密集(无无效点)
主要字段说明
header
:包含时间戳和坐标系的标准 ROS 消息头。
stamp
:时间戳,指示数据采集的时间。frame_id
:坐标系ID,指示点云数据所属的参考坐标系。
height
:点云的高度,表示有多少行数据。
width
:点云的宽度,表示每行有多少点。对于无组织的点云,width 表示点云中的总点数。
is_bigendian
:表示数据的字节顺序是否为大端格式。
point_step
:每个点在数据数组中占用的字节数。用于辅助解析 data 数组中的每个点。
row_step
:每行点云数据占用的字节数。
data
:以字节流形式存储的实际点云数据,包括点的 x, y, z 坐标。
is_dense
:表示点云数据中是否存在无效点。
回调函数实例
cpp
void lidarCallback(sensor_msgs::msg::PointCloud2::SharedPtr lidar_msg) {
pcl::PointCloud<pcl::PointXYZI>::Ptr pc_pcl(new pcl::PointCloud<pcl::PointXYZI>());
pcl::fromROSMsg<pcl::PointXYZI>(*lidar_msg, *pc_pcl);
for (const auto& pc : pc_pcl->points) {
/* <Customed processing procedure > */
}
}
测试方法
- 订阅 LIDAR 消息数据:
bash
ros2 topic echo /livox/lidar
注意事项
- 获取LiDAR数据时,应先确保 LiDAR 节点已正常启动且正在发布
livox/lidar
topic。