ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want the equivalent "ROS Time" as in ROS 1, e.g. might return wall clock time or simulated time (see https://wiki.ros.org/Clock#Using_Simulation_Time_from_the_.2BAC8-clock_Topic), then you need to call now on a Node, see:

http://docs.ros2.org/ardent/api/rclcpp/classrclcpp_1_1_node.html#af706b231620f1c120b7ccd738ec31867

The reason you need to get "now" from a node in ROS 2 is because unlike ROS 1, there's no global node singleton and the ROS time clock requires things like parameters and topics to implement sim time. So in ROS 2 you need to have a node to use ROS time.

If you only ever care about real time (no simulated time), then I suggest either using a custom made rclcpp::Clock, which defaults to "System time":

http://docs.ros2.org/ardent/api/rclcpp/classrclcpp_1_1_clock.html#abe5646eb46910ea5bda2486d082a31ab

Or give it an argument of RCL_STEADY_TIME to get monotonically increasing time.

You can also just use std::chrono::system_clock or std::chrono::steady_clock if you're not using ROS time:

http://en.cppreference.com/w/cpp/chrono/system_clock

http://en.cppreference.com/w/cpp/chrono/steady_clock

If you want the equivalent "ROS Time" as in ROS 1, e.g. might return wall clock time or simulated time (see https://wiki.ros.org/Clock#Using_Simulation_Time_from_the_.2BAC8-clock_Topic), then you need to call now now() on a Node, see:

http://docs.ros2.org/ardent/api/rclcpp/classrclcpp_1_1_node.html#af706b231620f1c120b7ccd738ec31867

The reason you need to get "now" from a node in ROS 2 is because unlike ROS 1, there's no global node singleton and the ROS time clock requires things like parameters and topics to implement sim time. So in ROS 2 you need to have a node to use ROS time.

If you only ever care about real time (no simulated time), then I suggest either using a custom made rclcpp::Clock, which defaults to "System time":

http://docs.ros2.org/ardent/api/rclcpp/classrclcpp_1_1_clock.html#abe5646eb46910ea5bda2486d082a31ab

Or give it an argument of RCL_STEADY_TIME to get monotonically increasing time.

You can also just use std::chrono::system_clock or std::chrono::steady_clock if you're not using ROS time:

http://en.cppreference.com/w/cpp/chrono/system_clock

http://en.cppreference.com/w/cpp/chrono/steady_clock