PointCloud library publishing
I have a pcl::PointCloud<pointxyz> cloud and I need to publish it. It is NOT a kinect camera. Does anyone know how to do this? Is there some good sample code out there? I really need help here....
Thanks in advance, -Hunter A.
int main(int argc, char **argv)
{
ros::init(argc , argv , "laser_ReadOut");
ros::NodeHandle handler;
ros::Subscriber laserReader = handler.subscribe("scan", 10000, scanCallBack);
ros::Publisher laserOutput = handler.advertise<pcl::PointCloud<pcl::PointXYZ> >("/cloud_pcl", 100);
laserOutput.publish(correctedCloud.makeShared());
ros::spin();
return 0;
}//end main.
correctedCloud is declared above. It is modified after the scan call back is called.
I am publishing the topic here (This is my research, so I'm afraid the whole code cannot be posted publicly)
void makeOneCloud()
{
PointCloud combined;
//matchSlopes();
for (unsigned int x = 0; x < scans.size(); ++x)
{
PointCloud currentCorrected = scans.at(x).getCorrections();
for (unsigned int y = 0; y < currentCorrected.points.size(); ++y)
{
double py = currentCorrected.points.at(y).y;
double px = currentCorrected.points.at(y).x;
double pZ = Z;
pcl::PointXYZ toPush;
toPush.x = px; toPush.y = py; toPush.z = pZ;
combined.points.push_back(toPush);
}//end for y
}//end for x.
correctedCloud = combined;
combined.height = 1;
combined.width = combined.points.size();
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("FinalCorrections.pcd", combined, false);
laserOutput.publish(combined.makeShared());
ROS_INFO("Corrections Saved!");
scans.clear();
}//this method combines all the corrected shapes to a single point cloud.
Do you ever set the frame_id of the cloud? You'll need to set it to something in order for rviz to display it.
Thank you! It works now!