Robotics StackExchange | Archived questions

How to block subscriber callback?

Hello,

I am using Python and ROS-Indigo, just curious for some explanation here, if there is any way to block the callback methods of a Subscriber. I am aware that ROS handles the callbacks in separate thread. Please throw some lights. Thanks a lot!

Asked by sosoup on 2017-07-20 01:52:01 UTC

Comments

Answers

What do you mean by block? Do you want to sometimes stop the callback form executing when it receives a message? You can have a global or class variable that you toggle when you want change whether to callback will execute or not. And then when the callback is called, it can check that variable and simply return immediately if desired. This should work but there might be a better way to do it.

Asked by velveteenrobot on 2017-07-20 14:55:05 UTC

Comments

Placing the global or class variable flag inside the callback method itself wont block the execution of the callback. The use-case here is to hold the execution of the callback method, based on some conditional flag.

Asked by sosoup on 2017-07-21 01:19:23 UTC

I think you could either do this by controlling when you call ros::spinOnce(), or write a custom CallbackQueue implementation that you can (en|di)sable whenever needed.

The first would essentially block 'all of ROS' from doing anything, the latter would allow you to selectively block things. See also wiki/roscpp/Overview/Callbacks and Spinning - CallbackQueue::callAvailable() and callOne() and wiki/roscpp/Overview/Callbacks and Spinning - Advanced: Using Different Callback Queues.

Asked by gvdhoorn on 2017-07-21 01:41:42 UTC

Comments

Thanks for your response. I am afraid there is no spinOnce() alternative for ROS-Python. And rospy.spin() wont help cause spinning might be from any of the root node or a node that is started earlier than this node which contains the Subscriber and Callback. (Please correct me if I am wrong)

Asked by sosoup on 2017-07-21 02:39:01 UTC

You're right that things are different for rospy. I somehow missed that in your question.

It's slightly different, but you could do the same thing in rospy. See swri_rospy fi.

Asked by gvdhoorn on 2017-07-21 03:07:21 UTC

I think that's a good link to dig in. I will try to use the resource. Thank you for your support.

Asked by sosoup on 2017-07-21 04:06:59 UTC