Package rospy :: Module rostime :: Class Time

Class Time

source code

         object --+        
                  |        
roslib.rostime.TVal --+    
                      |    
    roslib.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
 
__add__(self, other)
Add duration to this time (Inherited from roslib.rostime.Time)
source code
 
__cmp__(self, other)
Compare to another time (Inherited from roslib.rostime.Time)
source code
 
__eq__(self, other)
Equals test for Time. (Inherited from roslib.rostime.Time)
source code
 
__ge__(self, other)
>= test for time values (Inherited from roslib.rostime.TVal)
source code
 
__getstate__(self)
support for Python pickling (Inherited from roslib.rostime.Time)
source code
 
__gt__(self, other)
> test for time values (Inherited from roslib.rostime.TVal)
source code
 
__hash__(self)
Time values are hashable. (Inherited from roslib.rostime.TVal)
source code
 
__le__(self, other)
<= test for time values (Inherited from roslib.rostime.TVal)
source code
 
__lt__(self, other)
< test for time values (Inherited from roslib.rostime.TVal)
source code
 
__ne__(self, other) (Inherited from roslib.rostime.TVal) source code
 
__nonzero__(self)
Check if time value is zero (Inherited from roslib.rostime.TVal)
source code
 
__repr__(self)
repr(x) (Inherited from roslib.rostime.Time)
source code
 
__setstate__(self, state)
support for Python pickling (Inherited from roslib.rostime.Time)
source code
 
__str__(self)
str(x) (Inherited from roslib.rostime.TVal)
source code
 
__sub__(self, other)
Subtract time or duration from this time (Inherited from roslib.rostime.Time)
source code
 
canon(self)
Canonicalize the field representation in this instance. (Inherited from roslib.rostime.TVal)
source code
bool
is_zero(self)
Returns: True if time is zero (secs and nsecs are zero) (Inherited from roslib.rostime.TVal)
source code
 
set(self, secs, nsecs)
Set time using separate secs and nsecs values (Inherited from roslib.rostime.TVal)
source code
long
to_nsec(self)
Returns: time as nanoseconds (Inherited from roslib.rostime.TVal)
source code
float
to_sec(self)
Returns: time as float seconds (same as time.time() representation) (Inherited from roslib.rostime.TVal)
source code
float
to_time(self)
Get Time in time.time() format. (Inherited from roslib.rostime.Time)
source code

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
  nsecs (Inherited from roslib.rostime.Time)
  secs (Inherited from roslib.rostime.Time)

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__

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
Overrides: roslib.rostime.Time.from_seconds

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: roslib.rostime.Time.from_sec