ROS中的Time
ros时间戳
头文件
#include "ros/time.h"
变量
ros::Time time;
数据格式
header:
seq: 278
stamp:
secs: 173
nsecs: 427000000
frame_id: "xx"
从消息获取数据
ros::Time time = msg->header.stamp;
时间戳转浮点
time2 = time.toSec();
浮点型转换为时间戳
msg.header.stamp = time2.fromSec();
cpp时间戳
头文件
#include <chrono>
变量
std::chrono::hours hour_time = std::chrono::hours(1);
std::chrono::minutes minutes_time = std::chrono::duration_cast<std::chrono::minutes>(hour_time);
std::chrono::seconds seconds_time = std::chrono::duration_cast<std::chrono::seconds>(hour_time);
std::chrono::milliseconds milliseconds_time = std::chrono::duration_cast<std::chrono::milliseconds>(hour_time);
std::chrono::microseconds microseconds_time = std::chrono::duration_cast<std::chrono::microseconds>(hour_time);
获取当前时间
auto t1 = std::chrono::high_resolution_clock::now();
时间差
auto elased_time = std::chrono::duration_cast<std::chrono::nanoseconds>(t2-t1).count()/1.0e9;//纳秒级别
使用.count() 转浮点
ROS中的Time
http://example.com/2022/04/21/rostime/