Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import rospy
00011 import time
00012
00013
00014
00015
00016
00017 class WallRate():
00018
00019 def __init__(self, rate):
00020 '''
00021 @param rate : rate in hertz. If rate = 0, then won't sleep
00022 @type float
00023 '''
00024 self.rate = rate
00025 self.period = 1.0 / rate if rate > 0.0 else 0.0
00026 self.recorded_time = time.time()
00027
00028 def sleep(self):
00029 current_time = time.time()
00030 elapsed = current_time - self.recorded_time
00031 if self.period - elapsed > 0:
00032 rospy.rostime.wallsleep(self.period - elapsed)
00033 self.recorded_time = time.time()