ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Cancelling callbacks

asked 2017-07-17 23:27:28 -0600

harbor gravatar image

Hello, I am very new to ROS and am trying to make the system work in a very specific way. I want to create a Publisher/Service that will send multiple instructions that would be read by other nodes. Depending on the response I receive from one of these nodes I want to be able to stop the other ones. For example lets say I have a node that works with an ultrasonic sensor and another that works with the motor controls. I send the ultrasonic sensor node a message to report when the robot is a certain distance from the wall while I send the motor node a message to move randomly (meaning that it will not exit its callback). How do I make it so that when the ultrasonic node sends back data I can stop the motor node?

Also I am using rospy

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-17 23:56:40 -0600

updated 2017-07-18 19:29:04 -0600

Hi Harbor,

Welcome to the ROS comunity!

Blocking your node inside a service or message callback is usually not a good idea. Good programming practices dictate that you should not block inside a callback, instead the callback should just take note of the data it received, return immediately and let another part of the code deal with the data that the callback received (maybe another thread).

If you want to be able to stop a task, then you should be using actionlib instead. There is plenty of tutorials and documentation to help you get started.

I hope this helps!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-07-17 23:27:28 -0600

Seen: 444 times

Last updated: Jul 18 '17