Package rospy :: Module rostime :: Class Duration

Class Duration

source code

         object --+        
                  |        
roslib.rostime.TVal --+    
                      |    
roslib.rostime.Duration --+
                          |
                         Duration

Duration represents the ROS 'duration' primitive type, which consists of two integers: seconds and nanoseconds. The Duration class allows you to add and subtract Duration instances, including adding and subtracting from Time instances.

Usage:

 five_seconds = Duration(5)
 five_nanoseconds = Duration(0, 5)

 print 'Fields are', five_seconds.secs, five_seconds.nsecs

 # Duration arithmetic
 ten_seconds = five_seconds + five_seconds
 five_secs_ago = rospy.Time.now() - five_seconds # Time minus Duration is a Time

 true_val = ten_second > five_seconds
Instance Methods
 
__init__(self, secs=0, nsecs=0)
Create new Duration instance.
source code
Duration
__abs__(self)
Absolute value of this duration (Inherited from roslib.rostime.Duration)
source code
 
__add__(self, other)
Add duration to this duration, or this duration to a time, creating a new time value as a result. (Inherited from roslib.rostime.Duration)
source code
 
__cmp__(self, other) (Inherited from roslib.rostime.Duration) source code
Duration
__div__(self, val)
Divide this duration by an integer or float (Inherited from roslib.rostime.Duration)
source code
 
__eq__(self, other) (Inherited from roslib.rostime.Duration) source code
Duration
__floordiv__(self, val)
Floor divide this duration by an integer or float (Inherited from roslib.rostime.Duration)
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.Duration)
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
Duration
__mul__(self, val)
Multiply this duration by an integer or float (Inherited from roslib.rostime.Duration)
source code
 
__ne__(self, other) (Inherited from roslib.rostime.TVal) source code
Duration
__neg__(self)
Returns: Negative value of this duration (Inherited from roslib.rostime.Duration)
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.Duration)
source code
 
__setstate__(self, state)
support for Python pickling (Inherited from roslib.rostime.Duration)
source code
 
__str__(self)
str(x) (Inherited from roslib.rostime.TVal)
source code
 
__sub__(self, other)
Subtract duration from this duration, returning a new duration (Inherited from roslib.rostime.Duration)
source code
Duration
__truediv__(self, val)
Divide this duration by an integer or float (Inherited from roslib.rostime.Duration)
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

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

Static Methods
Duration
from_sec(float_seconds)
Create new Duration instance from float seconds format. (Inherited from roslib.rostime.Duration)
source code
Properties
  nsecs (Inherited from roslib.rostime.Duration)
  secs (Inherited from roslib.rostime.Duration)

Inherited from object: __class__

Method Details

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

source code 

Create new Duration instance. secs and nsecs are integers and correspond to the ROS 'duration' primitive type.

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