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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.