ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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
For your example:
>>> 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
2 | No.2 Revision |
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
For your example:
>>> 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