Package rospy :: Module rostime :: Class Time

Class Time

source code

        object --+        
                 |        
genpy.rostime.TVal --+    
                     |    
    genpy.rostime.Time --+
                         |
                        Time

Time represents the ROS 'time' primitive type, which consists of two integers: seconds since epoch and nanoseconds since seconds. Time instances are mutable.

The Time.now() factory method can initialize Time to the current ROS time and 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())
Instance Methods
 
__init__(self, secs=0, nsecs=0)
Constructor: secs and nsecs are integers and correspond to the ROS 'time' primitive type.
source code
 
__repr__(self)
repr(x)
source code

Inherited from genpy.rostime.Time: __add__, __cmp__, __eq__, __getstate__, __hash__, __setstate__, __sub__, to_time

Inherited from genpy.rostime.TVal: __bool__, __ge__, __gt__, __le__, __lt__, __ne__, __nonzero__, __str__, canon, is_zero, set, to_nsec, to_sec

Inherited from object: __delattr__, __format__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Static Methods
Time
now()
Create new Time instance representing current time.
source code
Time
from_seconds(float_secs)
Use Time.from_sec() instead.
source code
Time
from_sec(float_secs)
Create new Time instance from a float seconds representation (e.g.
source code
Properties

Inherited from genpy.rostime.Time: nsecs, secs

Inherited from object: __class__

Method Details

__init__(self, secs=0, nsecs=0)
(Constructor)

source code 

Constructor: secs and nsecs are integers and correspond to the ROS 'time' primitive type. You may prefer to use the static from_sec() and now() factory methods instead.

Parameters:
  • secs (int) - seconds since epoch
  • nsecs (int) - nanoseconds since seconds (since epoch)
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

now()
Static Method

source code 

Create new 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.

Returns: Time
Time instance for current time

from_seconds(float_secs)
Static Method

source code 

Use Time.from_sec() instead. Retained for backwards compatibility.

Parameters:
  • float_secs (float) - time value in time.time() format
Returns: Time
Time instance for specified time

from_sec(float_secs)
Static Method

source code 

Create new Time instance from a float seconds representation (e.g. time.time()).

Parameters:
  • float_secs (float) - time value in time.time() format
Returns: Time
Time instance for specified time
Overrides: genpy.rostime.Time.from_sec