Skip to content

LiDAR Service Interface


Obtaining LiDAR Data

Introduction

The LiDAR service interface is used to subscribe to LiDAR data topics. livox/lidar. This topic uses sensor_msgs/msg/PointCloud2 message type containing the point cloud data collected by the robot's solid-state LIDAR.

Topic NameTopic TypeRole
livox/lidarsensor_msgs/msg/PointCloud2Subscriber
Message Structure
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                   # 点云是否密集(无无效点)
Main Field Description

header: A standard ROS message header that contains a timestamp and coordinate system.

  • stamp : Timestamp, indicating the time of data collection.
  • frame_id: Coordinate system ID, which indicates the reference coordinate system to which the point cloud data belongs.

height : The height of the point cloud, indicating how many rows of data there are.

width : The width of the point cloud, indicating how many points are in each row. For an unorganized point cloud, width represents the total number of points in the point cloud.

is_bigendian: Indicates whether the byte order of the data is in big-endian format.

point_step: The number of bytes each point occupies in the data array. Used to assist in parsing each point in the data array.

row_step: The number of bytes occupied by the point cloud data per row.
data : The actual point cloud data stored as a byte stream, including the x, y, z coordinates of the point.
is_dense: Indicates whether there are invalid points in the point cloud data.

Callback Function Instance
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 > */
    }
}
Test Method
  • Subscribe to LIDAR message data:
bash
ros2 topic echo /livox/lidar
Precautions
  • When obtaining LiDAR data, ensure that the LiDAR node is started and is being published livox/lidar topic.