- ros消息时间戳转换成double类型的时间
#include <ros/time.h>
double time =msg->header.stamp.toSec();
#效果等同于
double time =msg->header.stamp.sec+msg->header.stamp.nsec/1e9;
- double消息类型转换成ros时间戳
#include <ros/time.h>
#include <ros/impl/time.h>
msg.header.stamp=ros::Time().fromSec(x);
注:
头文件部分,如果已声明 #include <ros/ros.h> ,则上面的头文件可以不必再声明。
参考:https://zhuanlan.zhihu.com/p/471215834