In this example, we will see how to publish a point cloud data using the sensor_msgs/PointCloud2 message. The code will use PCL APIs for handling and creating the point cloud, and converting the PCL cloud data to the PointCloud2 message type.
You will get the example code pcl_publisher.cpp from the pcl_ros_tutorial/src folder:
#include <ros/ros.h> // point cloud headers #include <pcl/point_cloud.h> //Header which contain PCL to ROS and ROS to PCL conversion functions #include <pcl_conversions/pcl_conversions.h> //sensor_msgs header for point cloud2 #include <sensor_msgs/PointCloud2.h> main (int argc, char **argv) { ros::init (argc, argv, "pcl_create"); ROS_INFO("Started PCL publishing node"); ros::NodeHandle nh; ...