ros::spinOnce() ros::spin()
时间: 2024-05-31 14:07:28 浏览: 117
Programming Robots with ROS
In ROS, there are two commonly used functions for handling callbacks: ros::spinOnce() and ros::spin().
ros::spinOnce() allows ROS to process any pending callbacks once, but then returns control to the calling thread. This is useful when you have a loop that needs to keep running, but you need to periodically check for new data or events.
ros::spin(), on the other hand, is a blocking call that does not return control to the calling thread until the node is shut down. This is useful when you have a node that needs to run continuously and respond to events or data as they come in.
In general, you should use ros::spinOnce() if you have a loop that needs to keep running, and ros::spin() if you have a node that needs to run continuously. However, there are some cases where you may need to use both functions together, such as if you have multiple nodes running in the same process.
阅读全文