配置livox点云数据运行FAST-lio2
Ubuntu20.04系统安装Livox ROS Driver
1. 安装依赖包CMAKE
先要确保ROS和Livox-SDK安装成功!安装过程可参考:
ROS安装:https://blog.csdn.net/weixin_43994864/article/details/119703293
Livox-SDK安装:https://blog.csdn.net/weixin_43994864/article/details/119703681
2. 下载ws_livox文件
git clone https://github.com/Livox-SDK/livox_ros_driver.git ws_livox/src
如果运行太慢,可以直接从如下地址下载:https://github.com/Livox-SDK/Livox-SDK,然后解压
3. 开始构建livox_ros_driver
cd ws_livox
catkin_make
【如果安装driver2】
cd ~/livox_ws/src
git clone https://github.com/Livox-SDK/livox_ros_driver2.git ws_livox/src/livox_ros_driver2
cd ws_livox
source /opt/ros/noetic/setup.sh
./build.sh ROS1
4. 更新当前ROS包
source ./devel/setup.sh
【建议将source语句添加到bashrc中】
5.创建ROS功能包【配置点云转换,如果不需要自己转换可忽略】
使用如下camke代码与cpp代码创建ROS节点
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
livox_ros_driver
)
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/point_cloud2_iterator.h>
#include <livox_ros_driver/CustomMsg.h>
ros::Publisher pointcloud_pub;
void livoxCallback(const livox_ros_driver::CustomMsg::ConstPtr& msg) {
// 初始化 PointCloud2 消息
sensor_msgs::PointCloud2 cloud_msg;
cloud_msg.header = msg->header; // 保持时间戳和frame一致
cloud_msg.height = 1;
cloud_msg.width = msg->point_num;
cloud_msg.is_dense = false;
// 设置字段
sensor_msgs::PointCloud2Modifier modifier(cloud_msg);
modifier.setPointCloud2Fields(4,
"x", 1, sensor_msgs::PointField::FLOAT32,
"y", 1, sensor_msgs::PointField::FLOAT32,
"z", 1, sensor_msgs::PointField::FLOAT32,
"intensity", 1, sensor_msgs::PointField::FLOAT32);
modifier.resize(msg->point_num);
// 通过迭代器来填充 PointCloud2 的数据
sensor_msgs::PointCloud2Iterator<float> iter_x(cloud_msg, "x");
sensor_msgs::PointCloud2Iterator<float> iter_y(cloud_msg, "y");
sensor_msgs::PointCloud2Iterator<float> iter_z(cloud_msg, "z");
sensor_msgs::PointCloud2Iterator<float> iter_intensity(cloud_msg, "intensity");
for (size_t i = 0; i < msg->point_num; ++i) {
*iter_x = msg->points[i].x;
*iter_y = msg->points[i].y;
*iter_z = msg->points[i].z;
*iter_intensity = static_cast<float>(msg->points[i].reflectivity); // 转换 reflectivity
++iter_x; ++iter_y; ++iter_z; ++iter_intensity;
}
pointcloud_pub.publish(cloud_msg);
}
int main(int argc, char** argv) {
ros::init(argc, argv, "livox_to_pcl_converter");
ros::NodeHandle nh;
ROS_INFO("livox to pcd ==> /livox/lidar to /livox/pointcloud");
// 订阅 Livox 自定义消息
ros::Subscriber livox_sub = nh.subscribe("/livox/lidar", 10, livoxCallback);
// 发布 PointCloud2 消息
pointcloud_pub = nh.advertise<sensor_msgs::PointCloud2>("/livox/pointcloud", 10);
ros::spin();
return 0;
}
rviz
6.运行FAST-lio2
cd ~/$A_ROS_DIR$/src
git clone https://github.com/hku-mars/FAST_LIO.git
cd FAST_LIO
git submodule update --init
//该步骤可能很慢,可根据报错手动添加
cd ../..
catkin_make
source devel/setup.bash
cd ~/$FAST_LIO_ROS_DIR$
source devel/setup.bash
roslaunch fast_lio mapping_mid360.launch
roslaunch livox_ros_driver livox_lidar_msg.launch
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐



所有评论(0)