Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

sensor_msgs::PointCloud2 is already defined sensor message but an array of sensor_msgs::PointCloud2 is not. Therefore you will need to define your own custom message. Check the tutorials on how to create and use a custom message.
Your .msg file (for example you can name it PointClouds.msg) should look something like this:

sensor_msgs::PointCloud2[] pointclouds

Once you have created and included your msg, the following should work:

#include "your_pkg_name/PointClouds.h"
...
pcl::PointCloud<ClassPoint> out;
 ....
sensor_msgs::PointCloud2 out_msg;
pcl::toROSMsg(out, out_msg);

PointClouds clouds_msg(2); 
clouds_msg.pointclouds[0] = out_msg;
out_msg.header.frame_id = corner_frame_name;

pub_merged_clouds.publish(clouds_msg);

and your publisher:

pub_merged_clouds = nh.advertise<PointClouds>(merged_clouds_topic, 1);

sensor_msgs::PointCloud2 is already defined sensor message but an array of sensor_msgs::PointCloud2 is not. Therefore you will need to define your own custom message. Check the tutorials on how to create and use a custom message.
Your .msg file (for example you can name it PointClouds.msg) should look something like this:

sensor_msgs::PointCloud2[] pointclouds

Once you have created and included your msg, the following should work:

#include "your_pkg_name/PointClouds.h"
...
pcl::PointCloud<ClassPoint> out;
 ....
sensor_msgs::PointCloud2 out_msg;
pcl::toROSMsg(out, out_msg);

PointClouds your_pkg_name::PointClouds clouds_msg(2); 
clouds_msg.pointclouds[0] = out_msg;
out_msg; // or just clouds_msg.pointclouds.push_back(out_msg);
out_msg.header.frame_id = corner_frame_name;

pub_merged_clouds.publish(clouds_msg);

and your publisher:

pub_merged_clouds = nh.advertise<PointClouds>(merged_clouds_topic, 1);

sensor_msgs::PointCloud2 is already defined sensor message but an array of sensor_msgs::PointCloud2 is not. Therefore you will need to define your own custom message. Check the tutorials on how to create and use a custom message.
Your .msg file (for example you can name it PointClouds.msg) should look something like this:

sensor_msgs::PointCloud2[] pointclouds

Once you have created and included your msg, the following should work:

#include "your_pkg_name/PointClouds.h"
...
pcl::PointCloud<ClassPoint> out;
 ....
sensor_msgs::PointCloud2 out_msg;
pcl::toROSMsg(out, out_msg);

your_pkg_name::PointClouds clouds_msg(2); 
clouds_msg.pointclouds[0] = out_msg; // or just clouds_msg.pointclouds.push_back(out_msg);
out_msg.header.frame_id = corner_frame_name;

pub_merged_clouds.publish(clouds_msg);

and your publisher:

pub_merged_clouds = nh.advertise<PointClouds>(merged_clouds_topic, nh.advertise<your_pkg_name::PointClouds>(merged_clouds_topic, 1);