You can easily do that by creating multiple subscribers or a vector of subscribers and make all of them point at same callback function.
sicklms_subs = new ros::Subscriber[no_of_ugv];
for(int i = 0; i < no_of_ugv; i++)
{
ss.seekp(0);
ss << "/sicklms" << i << "/scan";
sicklms_subs[i] = nh.subscribe(ss.str(), 100, &mapper_direct::laserCallback, this);
}
Originally posted by ayush_dewan with karma: 1610 on 2013-02-24
This answer was NOT ACCEPTED on the original site
Post score: 2
Original comments
Comment by superawesomepandacat on 2013-02-25:
That works. But is it possible to accept multiple different topics of the same type in a single callback function?
Comment by ayush_dewan on 2013-02-25:
yeah it is possible to that. Every element of vector can be subscribed to a different message name and still can have same callback function. I hope this is what ur asking..
Comment by superawesomepandacat on 2013-02-25:
It seems like I phrased my original question incorrectly, apologies for that. What I meant was, say I have to two subscribed topics, A and B. I want to process both A and B in a single callback function at the same time, for example A+B. Just wondering if that's possible.
Comment by ayush_dewan on 2013-02-25:
I think its not possible to do that...ROS does not provide a direct functionality for it so u have to write ur callback function in a way that provides you this functionality.
Comment by superawesomepandacat on 2013-02-26:
Yeah I'm trying to figure that out. Thanks anyways :)
Comment by tfoote on 2013-03-02:
Please edit your question to reflect what you want to know.