Multiple publishers in a while loop

asked 2018-03-05 13:03:29 -0500

Georgee gravatar image

updated 2018-03-05 17:08:51 -0500

Hi there,

I want to loop while a certain criteria is met. The main problem is that I don't want to save the results of each loop and then publish them, for I need to optimize computational time. I would need to do some kind of

publisher[i]=publish[i-topic];

inside the loop. Is this possible?

EDIT: The loop takes care of the segmentation of several planes of the scene. I'm working with PointCloud Library and the message type would be pcl::PointCloud<pcl::pointxyz>. I said I must publish it inside the loop because in each iteration the PointCloud data gets smaller as it filters out the already calculated planes. It's not a concern that publish is slow, and publisher[i] means a vector of ros::Publisher, if that's even possible to do.

Thanks in advance.

edit retag flag offensive close merge delete

Comments

2

What is publisher[i]=publish[i-topic]; supposed to do? Additional code or description (update the question) that captures the types of the variables there might help answer that. (is topic an integer offset? publish[] is a vector of ros::Publisher?) Is the concern that publish() is slow?

lucasw gravatar image lucasw  ( 2018-03-05 14:52:08 -0500 )edit

Thank you for your response @lucasw , I hope I explained myself better now :D

Georgee gravatar image Georgee  ( 2018-03-05 17:09:29 -0500 )edit

std::vector<ros::Publisher> publishers; is fine, also publishers.push_back(nh.advertise<pcl::PointCloud<pcl::pointxyz> >("foo", 1)); or similar also works, it's something I've done before.

lucasw gravatar image lucasw  ( 2018-03-05 18:39:33 -0500 )edit

Thanks a lot for your help. It is very useful. Nonetheless, I've encountered some problems in separating the data of each publisher. Remember I have to publish one set of data per loop, and I suppose I have to create threads because otherwise, with the while(ros::ok()), I don't know how to exit.

Georgee gravatar image Georgee  ( 2018-03-06 10:59:31 -0500 )edit

You'll have to put more of your code into the question to get more help. ros::shutdown() (if you have nothing else to do in your node) or break will get you out of that while loop.

lucasw gravatar image lucasw  ( 2018-03-06 12:51:05 -0500 )edit