[ros-users] Writing generic subscription callbacks
straszheim at willowgarage.com
Wed May 4 17:59:20 UTC 2011
On Wed, May 4, 2011 at 10:07 AM, Daniele Calisi <daniele.calisi at gmail.com>wrote:
> The problem comes when I try to write a generic subscriber: I tried with
> sub = new
> ros::Subscriber(rosNodeHandle->subscribe(url.getPath(), 1000,
> &RosAphModule::subscriptionCallback, this));
> but this cannot be done, since the callback should be something like:
> void RosAphModule::subscriptionCallback(const ros::Message::ConstPtr& msg)
> that is not allowed, because ros::Message is an abstract type and the
> compiler says what I paste at the end of this email... moreover, I would
> like to know how to get the topic the message was coming from (given the
> ros::Message& msg in the callback, I mean).
Looks tricky indeed... the compiler can only know which serialization
method to instantiate if it knows what message type to expect via the type
argument to subscribe<>. For instance, there is no procedure by which a ros
node, given an incoming message of unknown type, can look up a serialization
method in a table, since this table does not exist. If it did exist, there
would be no guarantee that it is complete, as the incoming message might
have been generated by code that this node does not have access to. Also,
to do anything with this message one would then need to type-switch or
something, which is quickly going to break down... there are just a lot of
problems here that might be better addressed with an alternate design.
So... can I ask you to elaborate on how this will all fit together?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ros-users