ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange

# Revision history [back]

I think the confusion stems from a mixing of ROS Time and Duration objects. In particular, subtracting two Time objects yields a Duration object, which cannot be directly compared to another Time object. The types of objects created by ROS Time & Duration arithmetic are explained on the ROS Wiki:
http://wiki.ros.org/rospy/Overview/Time#Time_and_Duration_arithmetic

>>> old = rospy.Time.now()
>>> new = rospy.Time.now()
>>> print type(now - old)
<class 'genpy.rostime.Duration'>
>>> dt = rospy.Time(secs=2)
>>> print type(dt)
<class 'rospy.rostime.Time'>


if instead we make dt a rospy.Duration, the if statement can be evaluated:

>>> dt = rospy.Duration(secs=2)
>>> print type(dt)
<class 'rospy.rostime.Duration'>
>>> (now - old) < dt
True


I think the confusion stems from a mixing of ROS Time and Duration objects. In particular, subtracting two Time objects yields a Duration object, which cannot be directly compared to another Time object. The types of objects created by ROS Time & Duration arithmetic are explained on the ROS Wiki:
http://wiki.ros.org/rospy/Overview/Time#Time_and_Duration_arithmetic

>>> old = rospy.Time.now()
>>> new = rospy.Time.now()
>>> print type(now type(new - old)
<class 'genpy.rostime.Duration'>
>>> dt = rospy.Time(secs=2)
>>> print type(dt)
<class 'rospy.rostime.Time'>


if instead we make dt a rospy.Duration, the if statement can be evaluated:

>>> dt = rospy.Duration(secs=2)
>>> print type(dt)
<class 'rospy.rostime.Duration'>
>>> (now (new - old) < dt
True