Multiple publishers in a while loop
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.
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. (istopic
an integer offset? publish[] is a vector of ros::Publisher?) Is the concern that publish() is slow?Thank you for your response @lucasw , I hope I explained myself better now :D
std::vector<ros::Publisher> publishers;
is fine, alsopublishers.push_back(nh.advertise<pcl::PointCloud<pcl::pointxyz> >("foo", 1));
or similar also works, it's something I've done before.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.
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.