Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.08 KB

time.md

File metadata and controls

37 lines (28 loc) · 1.08 KB

rclcpp: Time

The rclcpp::Time and rclcpp::Duration are a significant departure from their ROS1 equivalents, but are more closely related to std::chrono. For an in-depth discussion comparing with std::chrono, see this discussion on ROS Discourse.

When porting certain ROS1 libraries, there may be significant usage of timestamps as floating-point seconds. To get floating point seconds from an rclcpp::Time:

// node is instance of rclcpp::Node
rclcpp::Time t = node.now();
double seconds = t.seconds();

There is no constructor for Time from seconds represented by a floating point, so you first need to convert to nanoseconds:

rclcpp::Time t(static_cast<uin64_t>(seconds * 1e9));

rclcpp::Duration does have functions to go both directions:

rclcpp::Duration d = rclcpp::Duration::from_seconds(1.0);
double seconds = d.seconds();

Unlike ROS1, sleeping does NOT occur from a Duration instance:

rclcpp::sleep_for(std::chrono::milliseconds(50));