Answering to your last comment:
1/ I wanted to know if their return type can be changed and if so, how.
=> I don't think so.
2/ I want to run a single callback function to handle the messages based on the topic they listen to.
=> well nothing stops you to call the same callback on differents topics, if their message types are the same.
If the message types differ,you can probably template your argument "msg_type::ConstPtr& msg" and then test inside your callback which message type you have received and execute different things depending on this type. I don't see why you would do so instead of creating multiple callbacks but it seems possible to me. ( I believe that the multiple callbaks would be created anyway, it's just that you wouldn't see it since your compiler would create thoses multiple callbacks for you )
3/ I have built the system with multiple callbacks, wanted to know if there is an alternative.
=> this looks like the exact same question as 2/
The real question is why do you want to have a single callback ?
The way you ask your questions, it seems it is because you need to aggregate information from multiple topics and you don't know how to do it ?
If that's really what you need to do, one way to do so is to use class method.
void Foo::callback(const std_msgs::StringConstPtr& message)
{
}
...
Foo foo_object;
ros::Subscriber sub = nh.subscribe("my_topic", 1, &Foo::callback, &foo_object);
//information available in foo_object
Edit with your added image :
What you want is a callback(msg1, msg2, msg3 ....) ?? I don't think that's possible. If you really want to have a single callback in your fb1 node, then you could create a new node "agregator" which create a new unique message from all other messages and then create only one callback in your main since you would have only one topic to receive
The question why you want a unique callback still remain.... If it's in order to share information, the answer is above, if it's to have a simpler/clearer code, just create all your nodehandler/subscriber inside a function "all_callbacks"..... if it's to synchronize your messages you can use a message filter http://wiki.ros.org/message_filters to synchronize the topics
Can you clarify why you think that would require the function to have a return type?
I want it to return a type so that I can call it through a header file and run multiple instances of the same header file. Reducing the size of my code as I currently have a callback for each subscriber.
I don't see why simply using the callback by class wouldn't solve your issue : http://wiki.ros.org/roscpp/Overview/P... part 2.3.2 ?
I fail to see how returning a type and registering a callback multiple times have anything to do with each other.
Callbacks are just functions or methods. There is nothing special about them other than that they have a
void
return type and accept a single arg (the msg).@gvdhoorn I wanted to know if their return type can be changed and if so, how. I want to run a single callback function to handle the messages based on the topic they listen to. I have built the system with multiple callbacks, wanted to know if there is an alternative.