0
$\begingroup$

Rosanswers logo

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


Originally posted by harbor on ROS Answers with karma: 3 on 2017-07-17

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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!


Originally posted by Martin Peris with karma: 5625 on 2017-07-17

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.