Rosanswers logo

I am very confused by the online documentation re this topic. I have a node with this publisher:

pointcloud_pub_ = nh_.advertise<pcl::PointCloud<pcl::PointXYZI> > ("/cloud", 1, false);

In the callback, this vector is populated, then published.

pcl::PointCloud<pcl::PointXYZI> cloud_xyzi_;

How can I simply convert cloud_xyzi_ to PointCloud2 at the final stage before publishing?

Originally posted by chris_ on ROS Answers with karma: 83 on 2015-01-19

Post score: 0


1 Answer 1


Rosanswers logo

You don't need to! Just include the following header:

#include "pcl_ros/point_cloud.h"

advertise your pointcloud_pub_ with type sensor_msgs::PointCloud2

pointcloud_pub_ = nh_.advertise<sensor_msgs::PointCloud2> ("/cloud", 1, false);

and call publish give the point cloud with your explizit type:

pointcloud_pub_.pub( cloud_xyzi_ );

It should implizitly convert between the types.....

Originally posted by Wolf with karma: 7555 on 2015-01-20

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by chris_ on 2015-01-20:
thank you, thats excellent.

Comment by l0g1x on 2015-02-05:
Is this the prefered way to fill a pointcloud2 message? I have a similar scenario where i have a C struct containing each points (x,y,z) values, and dont know how to directly fill the sensor_msgs/PointCloud2 msg


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.