雷达数据通信示例
Livox-ros-driver2 驱动包安装教程
Section titled “Livox-ros-driver2 驱动包安装教程”安装 Livox_ros_driver2 包
Section titled “安装 Livox_ros_driver2 包”找一个地方放工作空间(以主目录为例),在主目录下打开终端,输入:
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2![]()
解释: 在打开终端位置克隆 livox_ros_driver2 包,并新建工作空间 ws_livox,在工作空间 ws_livox 的 src 目录下安装。

安装 Livox-SDK2 包
Section titled “安装 Livox-SDK2 包”安装 cmake(如果已安装可跳过)
Section titled “安装 cmake(如果已安装可跳过)”sudo apt install cmake克隆 Livox-SDK2 包
Section titled “克隆 Livox-SDK2 包”在 ws_livox 的 src 目录下打开终端,执行:
git clone https://github.com/Livox-SDK/Livox-SDK2.git现在 livox_ros_driver2 包和 Livox-SDK2 包在同一目录下的。
构建编译环境
Section titled “构建编译环境”cd ./Livox-SDK2/mkdir buildcd buildcmake .. && make -j执行安装命令
Section titled “执行安装命令”sudo make install至此,Livox-SDK2 安装完毕。
加载环境配置
Section titled “加载环境配置”配置相关ROS环境
Section titled “配置相关ROS环境”以ROS1(melodic)为例:
source /opt/ros/melodic/setup.sh./build.sh ROS1加载 Livox 工作空间环境变量
Section titled “加载 Livox 工作空间环境变量”source ~/ws_livox/devel/setup.bash永久配置 Livox 工作空间环境变量(可选)
Section titled “永久配置 Livox 工作空间环境变量(可选)”echo "source ~/ws_livox/devel/setup.bash" >> ~/.bashrc刷新终端环境配置
Section titled “刷新终端环境配置”source ~/.bashrc检索功能包路径
Section titled “检索功能包路径”rospack find livox_ros_driver2若能输出包的路径,则说明 ROS 已识别 Livox-ros-driver2 驱动包。
参考地址:GitHub - Livox-SDK/livox_ros_driver2
激光雷达话题说明
Section titled “激光雷达话题说明”X30 的激光雷达话题如下:
| 话题名 | 描述 | 消息类型 | 频率 |
|---|---|---|---|
| /livox/lidar | 览沃激光雷达自定义格式点云数据 | livox_ros_driver2/CustomMsg | 10Hz |
| /lidar_points | 通用格式点云数据 | sensor_msgs/PointCloud2 | 10Hz |
其中话题 /livox/lidar 的消息类型 livox_ros_driver2/CustomMsg 是自定义消息类型:
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 line若要在机器狗终端使用 rostopic echo 命令查看该话题消息,需要执行:
source ~/jy_cog/drivers/setup.bash若要在本地终端使用 rostopic echo 命令查看该话题消息,需要先完成 Livox-ros-driver2 驱动包的安装。
开发者如需在自己的程序中订阅该话题,需要在程序中定义该自定义消息的结构。
激光雷达数据订阅示例代码
Section titled “激光雷达数据订阅示例代码”以下示例演示如何订阅 /livox/lidar 话题并解析点云数据:
#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 配置
Section titled “CMakeLists.txt 配置”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 配置
Section titled “package.xml 配置”<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