ROS2 equivalent of rospy.Time.from_sec(...)
Where in ROS1 you could use rospy.Time.from_sec(...)
to create a rospy.Time
object representing 1 second, in ROS2 you can use rclpy.time.Time(nanoseconds=...)
to achieve a similar effect.
import rclpy.time
# 5 nanoseconds after epoch
t = rclpy.time.Time(nanoseconds=5.0)
Note that the argument is given in nanoseconds, not seconds. To convert seconds to nanoseconds, multiply by 1e9
:
import rclpy.time
# 5 seconds after Epoch
t = rclpy.time.Time(nanoseconds=5.0 * 1e9)
As always, epoch refers to 1970-01-01 00:00:00 UTC
.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow