MRPT  1.9.9
time.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/Clock.h>
11 #include <mrpt/ros1bridge/time.h>
12 #include <cmath> // std::fmod
13 
14 namespace mrpt::ros1bridge
15 {
16 mrpt::system::TTimeStamp fromROS(const ros::Time& src)
17 {
18  // Use the signature of time_tToTimestamp() that accepts "double" with the
19  // fractional parts of seconds:
20  return mrpt::system::time_tToTimestamp(src.sec + src.nsec * 1e-9);
21 
22  const mrpt::Clock::duration time =
23  std::chrono::duration_cast<mrpt::Clock::duration>(
24  std::chrono::seconds(src.sec) + std::chrono::nanoseconds(src.nsec) +
25  std::chrono::seconds(11644473600));
26 
27  return mrpt::system::TTimeStamp(time);
28 }
29 
30 ros::Time toROS(const mrpt::system::TTimeStamp& src)
31 {
32  // Convert to "double-version of time_t", then extract integer and
33  // fractional parts:
34  const double t = mrpt::system::timestampTotime_t(src);
35  ros::Time des;
36  des.sec = static_cast<uint64_t>(t);
37  des.nsec = static_cast<uint64_t>(std::fmod(t, 1.0) * 1e9 + 0.5 /*round*/);
38  return des;
39 }
40 } // namespace mrpt::ros1bridge
std::chrono::duration< rep, period > duration
Definition: Clock.h:24
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
double timestampTotime_t(const mrpt::system::TTimeStamp t) noexcept
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
Definition: datetime.h:105
bool toROS(const mrpt::obs::CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Convert mrpt::obs::CObservationGPS -> sensor_msgs/NavSatFix The user must supply the "msg_header" fie...
Definition: gps.cpp:48
ROS message: http://docs.ros.org/api/sensor_msgs/html/msg/NavSatFix.html MRPT message: https://github...
Definition: gps.h:28
bool fromROS(const sensor_msgs::NavSatFix &msg, mrpt::obs::CObservationGPS &obj)
Convert sensor_msgs/NavSatFix -> mrpt::obs::CObservationGPS.
Definition: gps.cpp:20
mrpt::system::TTimeStamp time_tToTimestamp(const double t)
Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to T...
Definition: datetime.h:91



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020