Convert Header Timestamp to nanosecond Python ROS2 Foxy
Hi,
I have been trying to convert the message timestamp to nanoseconds (epoch time).
I checked the ROS2 Foxy C++ API and it has a member function nanoseconds
listed for the Time
class. Also I checked the code for time.py
on the foxy branch of ros2/rclpy and it also has a
@property
def nanoseconds(self):
return _rclpy.rclpy_time_point_get_nanoseconds(self._time_handle)
But I am getting this error AttributeError: 'Time' object has no attribute 'nanoseconds'
I am currently doing as below and not sure if it is the right method to do it:
cur_time_stamp = int(str(msg.header.stamp.sec) +
str(msg.header.stamp.nanosec))
Can someone please help me on how to convert a message timestamp to nanoseconds?
this may help https://github.com/ros2/rclpy/blob/ca...
So I should create a Time Object using something like this(assuming an msg
incoming_msg
):So the timestamps ROS messages are
builtin_interfaces.msg.Time
and are different from the Time object in rclpy.time? Is this difference in the Class type also valid for current ROS2 releases like Galactic or Humble ?