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

It does not seem like there is. There's a .seconds() method that was added to rclcpp durations:

https://github.com/ros2/rclcpp/issues/482

but it looks like that is not supported in rclpy:

>>> from rclpy.node import Node
>>> t1 = Node("blah").get_clock().now()
>>> t2 = Node("blah").get_clock().now()
>>> d = t2-t1
>>> type(d)
<class 'rclpy.duration.Duration'>
>>> dir(d)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', 
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_duration_handle', 
'from_msg', 'get_c_duration', 'nanoseconds', 'to_msg']

The example above is from ROS 2 Humble, but it's the same in the Rolling docs.

https://docs.ros.org/en/rolling/p/rclpy/api/time.html