当前位置:网站首页>大疆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

边栏推荐
- 关于卡尔曼滤波的协方差如何影响deepsort的跟踪效果的考虑
- Brief introduction of chip, memory and its key indicators I
- Introduction to the official functions of easyrecovery14 data recovery software
- Event capture and bubbling - what is the difference between them?
- The problem of torch loading custom models
- Create a container that does not depend on any underlying image
- Basic concepts of program, process, thread, coprocess, single thread and multi thread
- CentOS上使用Docker安装和部署Redis
- Ancient art - make good use of long tail keywords
- After adding a camera (camera) to the UAV in gazebo, the UAV cannot take off
猜你喜欢

Sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then judge sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then ju

Mysql database

About the new features of ES6

ZnS-DNA QDs近红外硫化锌ZnS量子点改性脱氧核糖核酸DNA|DNA修饰ZnS量子点

Build cloud native operating environment

Express framework

Esxi virtual machine starts, and the module "monitorloop" fails to power on

After adding a camera (camera) to the UAV in gazebo, the UAV cannot take off

Many of the world's top 500 enterprises gathered at the second digital Expo, and the digital industry curtain is about to open!

Linux安装Redis操作
随机推荐
Socket programming II: using Select
Go language learning
DataScience:数据生成之在原始数据上添加小量噪声(可自定义噪声)进而实现构造新数据(dataframe格式数据存储案例)
Speech and language processing (3rd ed. draft) Chapter 2 - regular expression, text normalization, editing distance reading notes
Express framework
Memo @restcontrolleradvice and exception interception class example
DNA修饰贵金属纳米颗粒|脱氧核糖核酸DNA修饰纳米金(科研级)
Boostrap
DNA(脱氧核糖核酸)供应|碳纳米管载核酸-DNA/RNA材料|DNA/RNA核酸修饰磁性纳米颗粒
Two ways of multi GPU training of pytorch
脱氧核糖核酸DNA改性近红外二区砷化镓GaAs量子点|GaAs-DNA QDs|DNA修饰GaAs量子点
肽核酸PNA-多肽PNA-TPP|Glt-Ala-Ala-Pro-Leu-pNA|Suc-Ala-Pro-pNA|Suc-AAPL-pNA|Suc-AAPM-pNA
Sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then judge sunflower: don't worry when you encounter computer vulnerabilities, understand clearly and then ju
How to avoid loopholes? Sunflower remote explains the safe use methods in different scenarios
What if the website server is attacked? Sunflower tips that preventing loopholes is the key
硫化镉CdS量子点修饰脱氧核糖核酸DNA|CdS-DNA QDs|近红外CdS量子点偶联DNA规格信息
Auto encoder (AE), denoising auto encoder (DAE), variable auto encoder (VAE) differences
Redis快速学习
Sunflower popularizes Science in an all-round way to avoid loopholes for your remote control equipment in time
GoLand writes Go program