Skip to content

Commit

Permalink
refactor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas authored Jul 6, 2017
1 parent 46ff237 commit 6af1e30
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions clients/rospy/src/rospy/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def __init__(self, hz, reset=False):
@param reset: if True, timer is reset when rostime moved backward. [default: False]
@type reset: bool
"""
self._reset = reset
# #1403
self.last_time = rospy.rostime.get_rostime()
self.sleep_dur = rospy.rostime.Duration(0, int(1e9/hz))
self._reset = reset

def _remaining(self, curr_time):
"""
Expand Down Expand Up @@ -101,13 +101,11 @@ def sleep(self):
curr_time = rospy.rostime.get_rostime()
try:
sleep(self._remaining(curr_time))
except rospy.exceptions.ROSTimeMovedBackwardsException as e:
if self._reset:
rospy.logwarn('Time jumped backward, resetting timers.')
self.last_time = rospy.rostime.get_rostime()
return
else:
raise rospy.exceptions.ROSTimeMovedBackwardsException(e)
except rospy.exceptions.ROSTimeMovedBackwardsException:
if not self._reset:
raise
self.last_time = rospy.rostime.get_rostime()
return
self.last_time = self.last_time + self.sleep_dur

# detect time jumping forwards, as well as loops that are
Expand Down

0 comments on commit 6af1e30

Please sign in to comment.