ROS时间戳:使用ros::Time::now打印当前时间
可以使用以下代码利用ros::Time::now打印当前时间:
#include <ros/ros.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, 'print_time');
ros::NodeHandle nh;
while (ros::ok())
{
ros::Time now = ros::Time::now();
ROS_INFO('Current time: %f', now.toSec());
ros::Duration(1.0).sleep();
}
return 0;
}
此代码会在每秒钟输出当前时间,以秒为单位。您可以在需要打印时间的ROS节点中使用类似的代码。
原文地址: https://www.cveoy.top/t/topic/oB8M 著作权归作者所有。请勿转载和采集!