[ros-users] NodeHandle.subscribe(...) - callbacks

Cedric Pradalier cedric.pradalier at mavt.ethz.ch
Sun Jul 4 15:03:15 UTC 2010


Hi,

I may be wrong but I think the spirit here would be to create one small 
inline function for each callback and then call the generic function 
therein with a specific argument. I have not seen anything which would 
do exactly what you want, but I'm not sure what would be the advantage 
of adding an argument to the subscribe call-back.

Alternatively, you could define a generic queue object with a callback, 
and pass the object to the subscriber:
MagicQueue magicQueue1, magicQueue2;
ros::Subscriber sub = 
n.subscribe("topic1",100,&MagicQueue::callback,magicQueue1);
ros::Subscriber sub = 
n.subscribe("topic2",100,&MagicQueue::callback,magicQueue2);

In python, this would be used with the "partial" function, which is 
basically creating a small lambda function at run-time.

HTH

On 07/04/10 15:10, Peter Müller wrote:
> Hi,
>
> I have started using ROS recently and played around with it to see how 
> it fits my needs. So far I could work out everything I needed. I just 
> have one little problem left.
>
> This is regarding the callbacks, which get executed when you subscribe 
> to a topic. Lets assume I subscribe to two (three, four...) topics, 
> and the callback method is always the same. Is there a way to tell, 
> which topic executed the callback method?
> For example:
>     ros::Subscriber sub = n.subscribe("topic1", 100, subCallback);
>     ros::Subscriber sub1 = n.subscribe("topic2", 100, subCallback);
>
> So when subCallback(..) gets executed I can tell if it came from sub 
> or sub1. Is that possible?
>
> Ideally I would like to add an argument to the subCallback method.
> For example:
> void chatterCallback(int queue_id, const std_msgs::StringConstPtr& msg)
>
> With queue_id being an int I defined when subscribing. Could I do that 
> with my own boost::bind(...)? If so, how?
>
>
>
> I looked over the NodeHandle.subscribe code but I believe there is 
> nothing which works the way I want it to?
>
> Any help is appreciated, thanks.
>
>
>
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>    


-- 
Dr. Cedric Pradalier
http://www.asl.ethz.ch/people/cedricp

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20100704/ba46f585/attachment-0003.html>


More information about the ros-users mailing list