Ask Your Question
3

Python Spin Once Equivalent

asked 2013-12-13 12:56:33 -0500

atp gravatar image

updated 2014-01-28 17:06:37 -0500

ngrennan gravatar image

Is there an equivalent to spin_once (C++) in ROS for Python?

In C++ I have a loop with spin_once and during each iteration of the loop the code checks a couple of global variables for changes and then does some action based on the value of those global variables. The global variables are based on messages from other nodes' topics to which my C++ ROS node is subscribed. How would this code structure translate into Python?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
7

answered 2013-12-16 00:07:25 -0500

demmeln gravatar image

No, there is no spin_once in rospy. In rospy the subscriber's callbacks are executed in separate threads. Google quickly produces these old questions including answers:

To translate your loop from C++ you could either check periodically in a loop in the main thread, or check in each of the callbacks. Either way you likely need some thread synchronization.

edit flag offensive delete link more
0

answered 2019-06-12 09:00:07 -0500

byque gravatar image

The rospy function wait_for_message() allowed me to receive one message from topic in Python.

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

2 followers

Stats

Asked: 2013-12-13 12:56:33 -0500

Seen: 21,372 times

Last updated: Dec 16 '13