How to convert sensor_msgs::pointcloud to sensor_msgs::pointcloud2

2.7k Views Asked by At

I am using the code [here][1] which have sensor_msgs::pointcloud. Can someone help me how to convert it to sensor_msgs::pointcloud2 [1]: https://github.com/Vidicon/2dscantoPointcloud/blob/master/src/lidar_transform.cpp

2

There are 2 best solutions below

0
On

This code is quite old and you shouldn't really be using PointCloud messages now. That being said, you can run the pointcloud_converter node to get your message out as a PointCloud2. Take this launch file for example:

<launch>
    </node name="pointcloud_converter" type="point_cloud_converter" pkg="point_cloud_converter">
        <remap from="points_in" to="/your_topic" />
        <remap from="points_out" to="/your_output_topic" />
    </node>
</launch>
0
On

You could use the method convertPointCloudToPointCloud2 from point_cloud_conversion.hpp