LiDAR Data Communication Example
Livox-ros-driver2 Driver Installation Tutorial
Section titled “Livox-ros-driver2 Driver Installation Tutorial”Install Livox_ros_driver2 Package
Section titled “Install Livox_ros_driver2 Package”Choose a location for the workspace (home directory as example). Open a terminal in the home directory and enter:
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2![]()
Explanation: Clone the livox_ros_driver2 package at the terminal location, creating a new workspace ws_livox, and install it in the src directory of workspace ws_livox.

Install Livox-SDK2 Package
Section titled “Install Livox-SDK2 Package”Install cmake (skip if already installed)
Section titled “Install cmake (skip if already installed)”sudo apt install cmakeClone Livox-SDK2 Package
Section titled “Clone Livox-SDK2 Package”Open a terminal in the src directory of ws_livox and execute:
git clone https://github.com/Livox-SDK/Livox-SDK2.gitNow the livox_ros_driver2 package and Livox-SDK2 package are in the same directory.
Build Compilation Environment
Section titled “Build Compilation Environment”cd ./Livox-SDK2/mkdir buildcd buildcmake .. && make -jExecute Installation Command
Section titled “Execute Installation Command”sudo make installLivox-SDK2 installation is now complete.
Load Environment Configuration
Section titled “Load Environment Configuration”Open a New Terminal
Section titled “Open a New Terminal”Configure ROS Environment
Section titled “Configure ROS Environment”Using ROS1 (melodic) as an example:
source /opt/ros/melodic/setup.sh./build.sh ROS1Installation Verification
Section titled “Installation Verification”Load Livox Workspace Environment Variables
Section titled “Load Livox Workspace Environment Variables”source ~/ws_livox/devel/setup.bashPermanently Configure Livox Workspace Environment Variables (Optional)
Section titled “Permanently Configure Livox Workspace Environment Variables (Optional)”echo "source ~/ws_livox/devel/setup.bash" >> ~/.bashrcRefresh Terminal Environment Configuration
Section titled “Refresh Terminal Environment Configuration”source ~/.bashrcSearch for Package Path
Section titled “Search for Package Path”rospack find livox_ros_driver2If the package path is output, ROS has recognized the Livox-ros-driver2 driver package.
Reference: GitHub - Livox-SDK/livox_ros_driver2
LiDAR Topic Description
Section titled “LiDAR Topic Description”X30 LiDAR topics are as follows:
| Topic Name | Description | Message Type | Frequency |
|---|---|---|---|
| /livox/lidar | Livox LiDAR custom format point cloud data | livox_ros_driver2/CustomMsg | 10Hz |
| /lidar_points | Generic format point cloud data | sensor_msgs/PointCloud2 | 10Hz |
The message type livox_ros_driver2/CustomMsg for topic /livox/lidar is a custom message type:
std_msgs/Header header uint32 seq time stamp string frame_iduint64 timebaseuint32 point_numuint8 lidar_iduint8[3] rsvdlivox_ros_driver2/CustomPoint[] points uint32 offset_time float32 x float32 y float32 z uint8 reflectivity uint8 tag uint8 lineTo use rostopic echo on the robot dog terminal to view this topic, run:
source ~/jy_cog/drivers/setup.bashTo use rostopic echo on the local terminal to view this topic, you need to complete the Livox-ros-driver2 driver package installation first.
If developers need to subscribe to this topic in their own programs, they need to define the custom message structure in their program.
LiDAR Data Subscription Example Code
Section titled “LiDAR Data Subscription Example Code”The following example demonstrates how to subscribe to the /livox/lidar topic and parse point cloud data:
#include "ros/ros.h"#include "livox_ros_driver2/CustomMsg.h"
int g_count = 0;
void lidarCallback(const livox_ros_driver2::CustomMsg::ConstPtr& msg){ g_count++;
ROS_WARN("\n===== cycle:%d =====", g_count);
ROS_WARN("header: "); ROS_WARN(" seq: %u", msg->header.seq); ROS_WARN(" stamp: "); ROS_WARN(" secs: %u", msg->header.stamp.sec); ROS_WARN(" nsecs: %u", msg->header.stamp.nsec); ROS_WARN(" frame_id: \"%s\"", msg->header.frame_id.c_str());
ROS_WARN("timebase: %lu", msg->timebase); ROS_WARN("point_num: %u", msg->point_num); ROS_WARN("lidar_id: %hhu", msg->lidar_id); ROS_WARN("rsvd: [%hhu, %hhu, %hhu]", msg->rsvd[0], msg->rsvd[1], msg->rsvd[2]);
ROS_INFO("points: "); for (size_t i = 0; i < msg->points.size(); ++i) { const auto& point = msg->points[i]; ROS_INFO(" - "); ROS_INFO(" offset_time: %u", point.offset_time); ROS_INFO(" x: %f, y: %f, z: %f", point.x, point.y, point.z); ROS_INFO(" reflectivity: %hhu, tag: %hhu, line: %hhu", point.reflectivity, point.tag, point.line); } ROS_WARN("---");}
int main(int argc, char **argv){ ros::init(argc, argv, "lidar_subscriber"); ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/livox/lidar", 1000, lidarCallback); ros::spin();
return 0;}CMakeLists.txt Configuration
Section titled “CMakeLists.txt Configuration”find_package(catkin REQUIRED COMPONENTS geometry_msgs roscpp rospy std_msgs message_generation livox_ros_driver2)
add_message_files(FILES CustomMsg.msg)generate_messages(DEPENDENCIES std_msgs livox_ros_driver2)
catkin_package( CATKIN_DEPENDS roscpp rospy std_msgs message_runtime livox_ros_driver2)
add_executable(lidar_subscriber src/lidar_subscriber.cpp)target_link_libraries(lidar_subscriber ${catkin_LIBRARIES})add_dependencies(lidar_subscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})package.xml Configuration
Section titled “package.xml Configuration”<build_depend>message_generation</build_depend><exec_depend>message_runtime</exec_depend><build_depend>livox_ros_driver2</build_depend><exec_depend>livox_ros_driver2</exec_depend>source devel/setup.bashrosrun livox_custom lidar_subscriber