(ROS1) Timer文档:Timers
在编写具有定时功能的节点时,在声明ros::Timer计时器节点以前,要写下类似如下功能的语句:
//The next two lines are important because this node should sync with the ros system time:
ros::spinOnce();
ros::Duration(0.1).sleep();
作用是使此节点跟ros系统正在进行的时间同步,否则,如果ros系统时间已经行进到15s,但是计时器定为10s,则该节点会判断时间已到(因为已经到15s了),立即会到时间。