The relation between ROS and PCL point cloud is a little bit complicated, at first, it was part of ROS, then it became a separate project and whole the time you need some serializer and deserializer to send and receive point cloud ROS messages. There are some old deprecated ways to do that and they still exist in the ROS documentation which confuses the programmers, so here is the right API to use:
converting a PCL point cloud to a ROS PCL message
first, include the corresponding headers:
1 2 |
#include <sensor_msgs/PointCloud2.h> #include <pcl_conversions/pcl_conversions.h> |
1 2 3 4 |
sensor_msgs::PointCloud2 object_msg; pcl::PointCloud::Ptr object_cloud; object_cloud.reset(new pcl::PointCloud); pcl::toROSMsg(*object_cloud.get(),object_msg ); |
converting ROS PCL message to a PCL pointcloud:
1 2 3 4 5 |
pcl::PointCloud::Ptr received_cloud_ptr; received_cloud_ptr.reset(new pcl::PointCloud); sensor_msgs::PointCloud2ConstPtr pointcloud_msg; pcl::fromROSMsg(*pointcloud_msg.get(), *received_cloud_ptr.get()); |
more about pcl point cloud and conversion