Difference between rospy.spin and rospy.sleep
Hi There! Whats the difference between rospy.spin nad rospy.sleep? Does rospy.rate affect rospy.spin?
Hi There! Whats the difference between rospy.spin nad rospy.sleep? Does rospy.rate affect rospy.spin?
rospy.spin()
will effectively go into an infinite loop until it receives a shutdown signal (e.g. ctrl-c
). During that loop it will process any events that occur, such as data received on a topic or a timer triggering, when they occur but otherwise it will sleep. You should use spin()
when your node doesn't do anything outside of its callbacks.
rospy.sleep()
will do the same as rospy.spin()
but only for the length of time you specify. It is used when your node has to do some kind of regular processing in addition to responding to topic events, timer events, etc. For example, a node controlling a motor will need to do some processing at regular intervals to set the motor's desired speed.
(Technically, what both are doing is sleeping your main thread and allowing other, internal threads to do their work.)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2019-09-02 15:05:45 -0600
Seen: 4,370 times
Last updated: Sep 02 '19
How to build Autoware after modify source code?
Why does my compiler warn at usage of operators of ros::TimeBase?
Can custom messages be located within a package?
How to make ardrone_autonomy work on ROS Melodic?
rosbag2_bag_v2_plugins install issue
ROS packages for an outdoor 'Roomba' robot