Time represents the ROS 'time' primitive type, which consists of two integers: seconds since epoch and nanoseconds since seconds. Time instances are mutable.
The L{Time.now()} factory method can initialize Time to the current ROS time and L{from_sec()} can be used to create a Time instance from the Python's time.time() float seconds representation.
The Time class allows you to subtract Time instances to compute Durations, as well as add Durations to Time to create new Time instances.
- Usage::
now = rospy.Time.now() zero_time = rospy.Time()
print 'Fields are', now.secs, now.nsecs
# Time arithmetic five_secs_ago = now - rospy.Duration(5) # Time minus Duration is a Time five_seconds = now - five_secs_ago # Time minus Time is a Duration true_val = now > five_secs_ago
# NOTE: in general, you will want to avoid using time.time() in ROS code import time py_time = rospy.Time.from_sec(time.time())
Class Method | from |
Use Time.from_sec() instead. Retained for backwards compatibility. |
Static Method | now |
Create new L{Time} instance representing current time. This can either be wall-clock time or a simulated clock. It is strongly recommended that you use the now() factory to create current time representations instead of reading wall-clock time and create Time instances from it. |
Method | __init__ |
Constructor: secs and nsecs are integers and correspond to the ROS 'time' primitive type. You may prefer to use the static L{from_sec()} and L{now()} factory methods instead. |
Method | __repr__ |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Use Time.from_sec() instead. Retained for backwards compatibility.
@param float_secs: time value in time.time() format @type float_secs: float @return: Time instance for specified time @rtype: L{Time}
Create new L{Time} instance representing current time. This can either be wall-clock time or a simulated clock. It is strongly recommended that you use the now() factory to create current time representations instead of reading wall-clock time and create Time instances from it.
@return: L{Time} instance for current time @rtype: L{Time}