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?
Asked by vanguard478 on 2022-09-30 07:47:28 UTC
Comments
this may help https://github.com/ros2/rclpy/blob/ca1d26d6ce36414425f205ea0675aeb6cc969b46/rclpy/rclpy/time.py#L142-L146
Asked by ravijoshi on 2022-09-30 08:07:53 UTC
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 ?Asked by vanguard478 on 2022-09-30 10:52:57 UTC