当前位置:网站首页>ROS knowledge: reading point cloud data files

ROS knowledge: reading point cloud data files

2022-06-23 11:59:00 Mr anhydrous

One 、 Point cloud file

Point cloud files are actually very simple , It is simply a file composed of the coordinates of a large group of points . This document describes PCD( Point cloud data ) File format , And it's in the point cloud Library (PCL) How to use the . Open one pcd file , See the following :

For more details, see :(3 Bar message ) ROS knowledge : Point cloud file .pcd Format

  here , We from github Get a point cloud file on model.pcd, The following will demonstrate how to start from ROS Read .

Two 、 Create a workspace :

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace


cd ~/catkin_ws
catkin_make
catkin_create_pkg load_pcd pcl_conversions pcl_ros roscpp sensor_msgs

3、 ... and 、 Generate node program

        stay catkin_ws/src Generate a new folder load_pcd, In it src Create a new one in the directory load_pcd.cpp file , And copy the following code :

#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_output", 1);
  pcl::PointCloud<pcl::PointXYZ> cloud;
  sensor_msgs::PointCloud2 output;
  pcl::io::loadPCDFile ("/home/huatec/catkin_ws/src/load_pcd/src/model.pcd", cloud);   
//  Modify yourself pcd File path 
  //Convert the cloud to ROS message
  pcl::toROSMsg(cloud, output);
  output.header.frame_id = "odom";
  
  //this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer    
    //!!! This step needs attention , It's the back rviz Of  fixed_frame  a key !!
  ros::Rate loop_rate(1);
  while (ros::ok())
  {
    pcl_pub.publish(output);
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}

Enter here load_pcd/src, take model.pcd It's also in this directory . 

3、 ... and 、 modify CMakelist file

add_executable(load_pcd src/load_pcd.cpp)
add_targate_libarary (read_pcd ${catkin_LIBRARIES})

Four 、package.xml Add :

<build_depend>libpcl-all-dev</build_depend>
<exec_depend>libpcl-all</exec_depend>

5、 ... and 、 Compile function packs


5.1 Terminal access catkin_ws Catalog :

catkin_make

After the compilation is successful OK 了 .

5.2 stay RVIZ Inside display

   1) At respective terminals :

roscore

   2) Open the terminal again

rosrun load_pcd load_pcd

Sure rostopic list to glance at /output Has this news been released yet

 3) Open the terminal again

      rosrun rviz rviz

open rviz after add One pointcloud2, Topic choice pcl_output You can see the image .

It may be opening rviz after status newspaper tf Related error , Then open a terminal and execute the following commands :

rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 map odom 100

6、 ... and 、 Results show

Get into rviz after ,add Button , Join in pointcloud2, So it shows model.pcd Image :

原网站

版权声明
本文为[Mr anhydrous]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231152017932.html