ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Convert pcl::PointCloud<pcl::PointCloudXYZI> to pcl::PCLPointCloud2

asked 2015-01-19 21:52:33 -0600

chris_ gravatar image

updated 2015-01-19 21:52:58 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-20 01:19:25 -0600

Wolf gravatar image

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.....

edit flag offensive delete link more

Comments

thank you, thats excellent.

chris_ gravatar image chris_  ( 2015-01-20 01:49:57 -0600 )edit

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

l0g1x gravatar image l0g1x  ( 2015-02-05 10:08:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-19 21:52:33 -0600

Seen: 1,550 times

Last updated: Jan 20 '15