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

rclcpp::Time() without nodehandles in ROS2 Foxy

asked 2020-11-19 05:52:10 -0600

Divyanshu gravatar image

I am trying to create a controller plugin for the nav2 stack. As per the tutorials, I have rclcpp_lifecycle::LifecycleNode shared pointer which I use to create a clock (node->get_clock()) and use clock-> now() to get the latest time. I have created libraries which are used with this plugin. I want to get the latest time in these libraries without having to pass down the node handles.

In ROS1 we could create node handles in the library itself and get the latest time using ros::Time::now() but the library itself wouldn't be a node. However, I don't think we can have a ros2 node handle spawned out of the blue, without it being tied to an actual node. I don't want to have to pass a node handle 3 layers into this library for two timers that can be paused with simulation time. I have seen some examples where to get the latest time without node handles they use rclccpp::Time() but I am not sure what it means and what it does. Also, is there an alternative to ros::Time::now() or ros::Time(0) in ROS2 without passing down the node handles as mentioned earlier and what exactly does rclcpp::Time() mean without any node initialisation?

I am using ROS2 Foxy in Ubuntu 20.04

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-20 03:50:31 -0600

tfoote gravatar image

The short answer is that you cannot get time now without a Node instance. In ROS 1 you could create a NodeHandle from nothing as long as you'd initialized ROS because there was a global node instance actually under the hood. And the bare functions could rely on that. In ROS 2 we've removed that global under the hood so you cannot invoke the bare functions, nor construct a Node without appropriate context.

You can create Time objects themselves, but you have to get now() from a clock object. And that clock object must have a TimeSource attached, which is provided by the Nodeinstance. The use of rclcpp::Time is forced to wall time and is not recommended for general use. There's more to extend/implement in the Time API see: https://github.com/ros2/rclcpp/issues... and https://github.com/ros2/rclcpp/issues...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-11-19 05:45:57 -0600

Seen: 3,273 times

Last updated: Nov 20 '20