Read and publish point cloud from a PCD file

This code can read a PCD file and publish the point cloud in the /pcl_output topic. The code pcl_read.cpp is available in the src folder.

#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> main(int argc, char **argv) { ros::init (argc, argv, "pcl_read"); ROS_INFO("Started PCL read node"); ros::NodeHandle nh; ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1); sensor_msgs::PointCloud2 output; pcl::PointCloud<pcl::PointXYZ> cloud; //Load test.pcd file pcl::io::loadPCDFile ("test.pcd", cloud); pcl::toROSMsg(cloud, output); output.header.frame_id ...

Get ROS Programming: Building Powerful Robots now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.