ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Interrupting rospy.spin() or writing a custom loop that does the equivalent.

asked 2017-01-20 17:48:20 -0500

lwoiceshyn gravatar image


Is there a way to exit the rospy.spin() loop without completely shutting down the node?

Or possibly is there a way to write my own equivalent rospy.spin() loop which answers service calls periodically until I stop it?

Any help or comments are appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-21 01:15:29 -0500

NEngelhard gravatar image

The code of rospy.spin can be found on github/roscom

It boils down to

while not rospy.core.is_shutdown():

So you can write your node around this loop and leave the loop whenever you want.

edit flag offensive delete link more



rospy.spin() is not even really needed to have a properly working ROS python node. rospy.spin() is just provided to have something that allows a similar control flow to be setup to how roscpp does things.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 03:14:47 -0500 )edit

Question Tools



Asked: 2017-01-20 17:48:20 -0500

Seen: 9,105 times

Last updated: Jan 21 '17