ROS中发布GNSS和点云PCD信息

2024-05-03 11:18
文章标签 发布 信息 ros 点云 gnss pcd

本文主要是介绍ROS中发布GNSS和点云PCD信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.发布gnss

ros::Publisher pub = nh.advertise<nmea_msgs::Sentence>("/nmea_sentence", 1);
// Publish all topics with the same ROS time stamp.
ros::Time topic_publish_time = ros::Time::now();// === NMEA Sentence ===
msg.header.stamp = topic_publish_time;
msg.header.frame_id = "/gps";
// 发布间隔
ros::WallDuration(0.1).sleep();
msg.sentence = `$GPGGA,063201.60,3016.3898531,N,12004.0198533,E,4,19,0.7,6.795,M,7.038,M,1.6,1792*78;
pub.publish(msg);

发布后的完整信息为
header:
seq: 156476
stamp:
secs: 1427157704
nsecs: 536139011
frame_id: “/gps”
sentence: “$GNRMC,004129.40,A,3514.0854393,N,13700.3090060,E,5.9921,147.814,240315,7.320,E,D*10”

2.发布pcd文件

void loadMap()
{std::vector<std::string> pcd_paths;string filePath = "/home/rtour/Desktop/data/2019-12-31-14-32-00-886/Lidar/lidar0/";vector<string> files;//vector<string> filesname;//获取该路径下的所有文件路径get_filelist_from_dir(filePath, files);ros::NodeHandle n;pcd_pub = n.advertise<sensor_msgs::PointCloud2>("points_raw", 1, true);//遍历所有路径for (int i = 1; i < files.size(); ++i) {string dir = filePath;std::string path(dir.append(files[i]));pcd_paths.push_back(path);sensor_msgs::PointCloud2 pcd;if (pcl::io::loadPCDFile(path, pcd) == -1) {std::cerr << "load failed " << path << std::endl;}int err = 0;// Give time to set up pub/subros::WallDuration(0.1).sleep();publish_pcd(pcd,&err);}
}
void publish_pcd(sensor_msgs::PointCloud2 pcd, const int* errp = NULL)
{if (pcd.width != 0) {cout<<"pub"<<endl;pcd.header.frame_id = "/velodyne";ros::Time topic_publish_time = ros::Time::now();pcd.header.stamp = topic_publish_time;pcd_pub.publish(pcd);if (errp == NULL || *errp == 0) {//stat_msg.data = true;//stat_pub.publish(stat_msg);}}
}

3.平移和旋转pcd

string filePath = "/home/rtour/.autoware/lz/xxtest.pcd";pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ());if (pcl::io::loadPCDFile (filePath, *source_cloud) < 0)  {std::cout << "Error loading point cloud " << filePath << std::endl << std::endl;return;}/* Reminder: how transformation matrices work :|-------> This column is the translation| 1 0 0 x |  \| 0 1 0 y |   }-> The identity 3x3 matrix (no rotation) on the left| 0 0 1 z |  /| 0 0 0 1 |    -> We do not use this line (and it has to stay 0,0,0,1)METHOD #1: Using a Matrix4fThis is the "manual" method, perfect to understand but error prone !*/// Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)float theta = -M_PI/3; // The angle of rotation in radians/*  METHOD #2: Using a Affine3fThis method is easier and less error prone*/Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();// Define a translation transform_2.translation() << 31.935742, 720.038504 ,6.741113;// The same rotation matrix as before; theta radians arround Z axistransform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));// Print the transformationprintf ("\nMethod #2: using an Affine3f\n");std::cout << transform_2.matrix() << std::endl;// Executing the transformationstd::cout << "transform start" << std::endl;pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud (new pcl::PointCloud<pcl::PointXYZ> ());// You can either apply transform_1 or transform_2; they are the samepcl::transformPointCloud (*source_cloud, *transformed_cloud, transform_2);//保存为一个新的pcd文件 pcl::io::savePCDFileASCII("/home/rtour/.autoware/lz/jh.pcd", *transformed_cloud);
std::cout << "transform end" << std::endl;

这篇关于ROS中发布GNSS和点云PCD信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/956618

相关文章

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

售价599元起! 华为路由器X1/Pro发布 配置与区别一览

《售价599元起!华为路由器X1/Pro发布配置与区别一览》华为路由器X1/Pro发布,有朋友留言问华为路由X1和X1Pro怎么选择,关于这个问题,本期图文将对这二款路由器做了期参数对比,大家看... 华为路由 X1 系列已经正式发布并开启预售,将在 4 月 25 日 10:08 正式开售,两款产品分别为华

利用Python快速搭建Markdown笔记发布系统

《利用Python快速搭建Markdown笔记发布系统》这篇文章主要为大家详细介绍了使用Python生态的成熟工具,在30分钟内搭建一个支持Markdown渲染、分类标签、全文搜索的私有化知识发布系统... 目录引言:为什么要自建知识博客一、技术选型:极简主义开发栈二、系统架构设计三、核心代码实现(分步解析

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

SpringKafka消息发布之KafkaTemplate与事务支持功能

《SpringKafka消息发布之KafkaTemplate与事务支持功能》通过本文介绍的基本用法、序列化选项、事务支持、错误处理和性能优化技术,开发者可以构建高效可靠的Kafka消息发布系统,事务支... 目录引言一、KafkaTemplate基础二、消息序列化三、事务支持机制四、错误处理与重试五、性能优

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

一文详解SQL Server如何跟踪自动统计信息更新

《一文详解SQLServer如何跟踪自动统计信息更新》SQLServer数据库中,我们都清楚统计信息对于优化器来说非常重要,所以本文就来和大家简单聊一聊SQLServer如何跟踪自动统计信息更新吧... SQL Server数据库中,我们都清楚统计信息对于优化器来说非常重要。一般情况下,我们会开启"自动更新