Skip to content

LiDAR Data Communication Example

Livox-ros-driver2 Driver Installation Tutorial

Section titled “Livox-ros-driver2 Driver Installation Tutorial”

Choose a location for the workspace (home directory as example). Open a terminal in the home directory and enter:

Terminal window
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2

Clone 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.

Directory structure

Terminal window
sudo apt install cmake

Open a terminal in the src directory of ws_livox and execute:

Terminal window
git clone https://github.com/Livox-SDK/Livox-SDK2.git

Now the livox_ros_driver2 package and Livox-SDK2 package are in the same directory.

Terminal window
cd ./Livox-SDK2/
mkdir build
cd build
cmake .. && make -j
Terminal window
sudo make install

Livox-SDK2 installation is now complete.

Using ROS1 (melodic) as an example:

Terminal window
source /opt/ros/melodic/setup.sh
./build.sh ROS1

Load Livox Workspace Environment Variables

Section titled “Load Livox Workspace Environment Variables”
Terminal window
source ~/ws_livox/devel/setup.bash

Permanently Configure Livox Workspace Environment Variables (Optional)

Section titled “Permanently Configure Livox Workspace Environment Variables (Optional)”
Terminal window
echo "source ~/ws_livox/devel/setup.bash" >> ~/.bashrc

Refresh Terminal Environment Configuration

Section titled “Refresh Terminal Environment Configuration”
Terminal window
source ~/.bashrc
Terminal window
rospack find livox_ros_driver2

If the package path is output, ROS has recognized the Livox-ros-driver2 driver package.

Reference: GitHub - Livox-SDK/livox_ros_driver2

X30 LiDAR topics are as follows:

Topic NameDescriptionMessage TypeFrequency
/livox/lidarLivox LiDAR custom format point cloud datalivox_ros_driver2/CustomMsg10Hz
/lidar_pointsGeneric format point cloud datasensor_msgs/PointCloud210Hz

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_id
uint64 timebase
uint32 point_num
uint8 lidar_id
uint8[3] rsvd
livox_ros_driver2/CustomPoint[] points
uint32 offset_time
float32 x
float32 y
float32 z
uint8 reflectivity
uint8 tag
uint8 line

To use rostopic echo on the robot dog terminal to view this topic, run:

Terminal window
source ~/jy_cog/drivers/setup.bash

To 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.

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;
}
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})
<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>
Terminal window
source devel/setup.bash
rosrun livox_custom lidar_subscriber