当前位置:网站首页>大疆livox定制的格式CustomMsg格式转换pointcloud2
大疆livox定制的格式CustomMsg格式转换pointcloud2
2022-07-27 05:36:00 【代码多少钱一两】
官方livox_driver驱动livox雷达发出的点云topic有两种,一种是大疆览沃定制的格式CustomMsg格式,另一种是将CustomMsg格式
转换过的pointcloud2格式,参见
Livox雷达驱动程序发布点云格式CustomMsg、PointCloud2、pcl::PointXYZI、pcl::PointXYZINormal解析
现在将转换这部分的代码提取出来,方便 随时使用
- 创建ros功能包
mkdir -p livox_repub/src
cd livox_repub/src
catkin_init_workspace
cd ..
catkin_make
- livox_repub.cpp
cd src
mkdir livox_repub
cd livox_repub
vi package.xml
<?xml version="1.0"?>
<package>
<name>livox_repub</name>
<version>0.0.0</version>
<description>
This is a .
</description>
<maintainer email="[email protected]">xxx</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>tf</build_depend>
<build_depend>pcl_ros</build_depend>
<build_depend>livox_ros_driver</build_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>nav_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>tf</run_depend>
<run_depend>pcl_ros</run_depend>
<run_depend>livox_ros_driver</run_depend>
<test_depend>rostest</test_depend>
<test_depend>rosbag</test_depend>
<export>
</export>
</package>
vi CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(livox_repub)
SET(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -std=c++0x -std=c++14 -fexceptions -Wno-unused-local-typedefs")
find_package(OpenMP QUIET)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
nav_msgs
sensor_msgs
roscpp
rospy
std_msgs
pcl_ros
tf
livox_ros_driver
)
find_package(Eigen3 REQUIRED)
find_package(PCL REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(
${
catkin_INCLUDE_DIRS}
${
EIGEN3_INCLUDE_DIR}
${
PCL_INCLUDE_DIRS})
catkin_package(
CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy std_msgs
DEPENDS EIGEN3 PCL OpenCV
)
add_executable(livox_repub livox_repub.cpp)
target_link_libraries(livox_repub ${
catkin_LIBRARIES} ${
PCL_LIBRARIES} ${
OpenCV_LIBS})
vi livox_repub.cpp
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include "livox_ros_driver/CustomMsg.h"
typedef pcl::PointXYZINormal PointType;
typedef pcl::PointCloud<PointType> PointCloudXYZI;
ros::Publisher pub_pcl_out0, pub_pcl_out1;
uint64_t TO_MERGE_CNT = 1;
constexpr bool b_dbg_line = false;
std::vector<livox_ros_driver::CustomMsgConstPtr> livox_data;
void LivoxMsgCbk1(const livox_ros_driver::CustomMsgConstPtr& livox_msg_in) {
livox_data.push_back(livox_msg_in);
if (livox_data.size() < TO_MERGE_CNT) return;
pcl::PointCloud<PointType> pcl_in;
for (size_t j = 0; j < livox_data.size(); j++) {
auto& livox_msg = livox_data[j];
auto time_end = livox_msg->points.back().offset_time;
for (unsigned int i = 0; i < livox_msg->point_num; ++i) {
PointType pt;
pt.x = livox_msg->points[i].x;
pt.y = livox_msg->points[i].y;
pt.z = livox_msg->points[i].z;
float s = livox_msg->points[i].offset_time / (float)time_end;
pt.intensity = livox_msg->points[i].line +livox_msg->points[i].reflectivity /10000.0 ; // The integer part is line number and the decimal part is timestamp
pt.curvature = s*0.1;
pcl_in.push_back(pt);
}
}
unsigned long timebase_ns = livox_data[0]->timebase;
ros::Time timestamp;
timestamp.fromNSec(timebase_ns);
sensor_msgs::PointCloud2 pcl_ros_msg;
pcl::toROSMsg(pcl_in, pcl_ros_msg);
pcl_ros_msg.header.stamp.fromNSec(timebase_ns);
pcl_ros_msg.header.frame_id = "/livox";
pub_pcl_out1.publish(pcl_ros_msg);
livox_data.clear();
}
int main(int argc, char** argv) {
ros::init(argc, argv, "livox_repub");
ros::NodeHandle nh;
ROS_INFO("start livox_repub");
ros::Subscriber sub_livox_msg1 = nh.subscribe<livox_ros_driver::CustomMsg>(
"/livox/lidar", 100, LivoxMsgCbk1);
pub_pcl_out1 = nh.advertise<sensor_msgs::PointCloud2>("/livox_pcl0", 100);
ros::spin();
}
- 编译运行
cd ../../
catkin_make
source devel/setup.bash
roslaunch livox_repub livox_repub.launch
注意:这个包是要先订阅CustomMsg的话题/livox/lidar,然后发布PointCloud2格式的"/livox_pcl0"话题,所以不论是实时驱动livox-driver还是通过bag包发布/livox/lidar,都需要确保有/livox/lidar才能有转换结果
转换后的PointCloud2点云可以通过rviz显示,终端输
rviz
Fixed Frame设置为livox,点云设置为/livox_pcl0
ros graph

边栏推荐
- 基于SSM学生成绩管理系统
- 如何删除或替换EasyPlayer流媒体播放器的loading样式?
- Inventory of the world's six most technologically competent smart contract audit companies in 2022
- 阿里云短信验证第三方接口(快速使用)
- Event capture and bubbling - what is the difference between them?
- Li Hongyi 2020 deep learning and human language processing dlhlp conditional generation by RNN and attention-p22
- The difference between malloc and new - Practical chapter
- deepsort源码解读(五)
- DNA科研实验应用|环糊精修饰核酸CD-RNA/DNA|环糊精核酸探针/量子点核酸探针
- Matlab drawing (ultra detailed)
猜你喜欢

智能安防视频平台EasyCVR出现通道列表为空情况的原因是什么?

如何删除或替换EasyPlayer流媒体播放器的loading样式?

Customer cases | focus on process experience to help bank enterprise app iteration

DNA modified noble metal nanoparticles | DNA modified gold nanoparticles (scientific research level)

O2O电商线上线下一体化模式分析

What is the reason why dragging the timeline is invalid when playing device videos on the easycvr platform?

Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places

Boostrap

Express receive request parameters

客户案例 | 聚焦流程体验,助银行企业APP迭代
随机推荐
Go language learning
Tips - completely delete the files on the USB flash drive
Linux Installation and uninstallation of MySQL
Recommended by the world's most technologically competent smart contract security audit company in 2022
如何让最小 API 绑定查询字符串中的数组
Inventory of the world's six most technologically competent smart contract audit companies in 2022
NAT (network address translation)
Variance and covariance
How can chrome quickly transfer a group of web pages (tabs) to another device (computer)
事件捕获方式和冒泡方式—它们的区别是什么?
Socket programming II: using Select
脱氧核糖核酸DNA修饰氧化锌|DNA修饰纳米金颗粒|DNA偶联修饰碳纳米材料
Event capture and bubbling - what is the difference between them?
聊聊大火的多模态
Esxi virtual machine starts, and the module "monitorloop" fails to power on
Customer cases | focus on process experience to help bank enterprise app iteration
FTX US launched FTX stocks, striding forward to the mainstream financial industry
EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?
DNA修饰贵金属纳米颗粒|脱氧核糖核酸DNA修饰纳米金(科研级)
Ftx.us launched stock and ETF trading services to make trading more transparent