Understanding ROS: finishing the basic concepts


This article is mainly a brief record of some basic concepts, which will be updated from time to time.

ROS reference learning website

ros official website api check website: https://docs.ros.org/en/api/
ros Wiki: http://wiki.ros.org/
ros wiki Chinese version: http://wiki.ros.org/cn
ros Chinese community: http://wiki.ros.org/cn/community
Chuangke Zhizhi: https://www.ncnynl.com/

ros::spin()与ros::spinOnce()

These two functions are called ROS message callback processing functions, which are used to process callback functions.

  • ros::spin(): The main program will not be executed here, and the callback function will continue to be executed. (After the program ends, for example, press ctrl-c, it will be executed).
  • ros::spinOnce(): Because it only calls back once, it can continue to execute subsequent programs after the call.

The ros::spin() function generally does not appear in the loop, because no other statements are called after the program executes to spin(). The usage of ros::spinOnce() is relatively flexible, but it is often necessary to consider the timing of calling the message, the calling frequency, and the size of the message pool. These must be coordinated according to the actual situation, otherwise it will cause data loss or delay error.

Note : Where there is a callback function, remember to add one of these two functions, otherwise the subscription message will not be received.

ros :: ok ()

Determine whether the ros node is operating normally, and return true if it is normal, so that ros::ok() returns false in the form:

  • SIGINT received terminal (Ctrl-C) signal
  • When another node with the same name is started, the previous node with the same name will be terminated first
  • ros::shutdown() is called
  • All ros::NodeHandles are destroyed

Note : ros::ok() only judges its own node, independent of other nodes.

Guess you like

Origin blog.csdn.net/QLeelq/article/details/111085177