How to convert a std::chrono::high_resolution_clock to ros::Time
I like to convert a chrono::high_resolution_clock to ros:Time?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
I like to convert a chrono::high_resolution_clock to ros:Time?
Hi ros::Time are sec and nsec since epoch
#include <iostream>
#include <chrono>
#include <ctime>
#include <ros/ros.h>
int main()
{
const auto p0 = std::chrono::time_point<std::chrono::high_resolution_clock>{};
const auto p3 = std::chrono::high_resolution_clock::now();
auto tstamp = p3 - p0;
int32_t sec = std::chrono::duration_cast<std::chrono::seconds>(tstamp).count();
int32_t nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(tstamp).count() % 1000000000UL;
std::cout << "sec: " << sec << " nsec: " << nsec << " since epoch: \n";
ros::Time n(sec, nsec);
return 0;
}
Asked: 2019-10-24 02:34:08 -0600
Seen: 2,539 times
Last updated: Oct 24 '19
how can I modify the value of a transform when playing back a bag file?
What's the best way to convert a ros message to a string or xml?
Change rostest max time allotted
Filling in time stamp data for rxplot
Chrony configuration and limitations
Conversion into ROS compatible timestamp