Advertisement

ROS学习笔记——PCD点云在rviz中显示

阅读量:

这篇文章介绍了如何利用PCL库将PCD文件转换为sensor_msgs::PointCloud2格式,并在Rviz中显示的过程。主要内容包括:使用pcl::toROSMsg函数进行数据转换,在Rviz中添加所需插件配置以显示点云数据,并提供了完整的代码示例和运行说明。

pcl实现了这部分功能,直接terminal输入:

rosrun pcl_ros pcd_to_pointcloud pcd_name 1(rate)


在上文中对ROS中的点云数据类型进行了介绍,在本篇文章中我们采用从pcl官网获取一个pcd文件的方法,并将其导入Rviz环境中进行展示。具体操作包括:首先,在Rviz中导入该pcd文件,并创建一个 ROS节点用于发布点云数据。其次,在该节点中使用Eigen库将原始PCD格式的数据转换为PointCloud2格式,并通过ROS bridge将处理后的数据传输到RViz,并在该环境中进行显示。源码如下:

复制代码
 #include<ros/ros.h>

    
 #include<pcl/point_cloud.h>
    
 #include<pcl_conversions/pcl_conversions.h>
    
 #include<sensor_msgs/PointCloud2.h>
    
 #include<pcl/io/pcd_io.h>//which contains the required definitions to load and store point clouds to PCD and other file formats.
    
  
    
 main (int argc, char **argv)
    
 {
    
   ros::init (argc, argv, "UandBdetect");
    
   ros::NodeHandle nh;
    
   ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output1", 1);
    
   pcl::PointCloud<pcl::PointXYZ> cloud;
    
   sensor_msgs::PointCloud2 output;
    
   pcl::io::loadPCDFile ("/home/uv/table_scene_lms400.pcd", cloud);
    
   //Convert the cloud to ROS message
    
   pcl::toROSMsg(cloud, output);
    
   output.header.frame_id = "odom1";//this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer
    
   ros::Rate loop_rate(1);
    
   while (ros::ok())
    
   {
    
     pcl_pub.publish(output);
    
     ros::spinOnce();
    
     loop_rate.sleep();
    
   }
    
   return 0;
    
 }

当加载一个PCD文件时,在Rviz中添加Point Cloud 2插件,并调整固定坐标系以订阅相应的主题消息。通过调用pcl::toROSMsg(cloud, output),将PCD数据转换为sensor_msgs::PointCloud2格式的ROS消息。

全部评论 (0)

还没有任何评论哟~