[ros-users] callback function on one topic with different message types

Radu Bogdan Rusu rusu at willowgarage.com
Tue Mar 23 15:49:45 UTC 2010

Though _not_ recommended, and if you really _cannot_ define multiple message types and multiple topics, _and_ if you 
only get one of the two types of messages for the entire duration while your node is up, you can get rid of the flag, 
and just subscribe to the same topic twice using different callbacks and different message types. The callback that 
answers first should invalidate the other. You can see an example of this working in point_cloud_converter.


Ugo Cupcic wrote:
> Ok, thanks for your answers. I'm now using a type flag in my message, 
> but I wanted to be sure I was doing it properly.
> Cheers,
> Ugo
> Brian Gerkey wrote:
>> On Tue, Mar 23, 2010 at 3:30 AM, Ugo Cupcic <ugo at shadowrobot.com> wrote:
>>> I was wondering how I can achieve to have different callback functions
>>> on the same topic depending on the message types.
>> hi Ugo,
>> In ROS, a topic can only carry messages of a single type.  We decided
>> early on that it would be too confusing if a topic could be of
>> multiple types. So roscpp doesn't support multi-type callback
>> registration.
>> (Note that the type of a topic actually can change over time, as it's
>> determined by the publisher that most recently advertised the topic.
>> But in a well-behaved ROS system, topics are stably typed).
>> 	brian.
>> _______________________________________________
>> ros-users mailing list
>> ros-users at code.ros.org
>> https://code.ros.org/mailman/listinfo/ros-users

| Radu Bogdan Rusu | http://rbrusu.com/

More information about the ros-users mailing list