I want to create trigger that runs something every 500 ms, and it should be without drifting over time. I have this code running to show something in pyopengl
def __init__(self):
...
self.t_on = time.clock()
...
def display_gl(self):
...
if (time.clock() - self.t_on) >= 0.500:
self.t_on = time.clock()
#do things
...
the clock is drifting over time, I think that's because the if
condition is catching the 500 ms moment after a little time.
Is there any way to avoid this drifting issue?
Solved:
changed:
if (time.clock() - self.t_on) >= 0.500:
self.t_on = time.clock()
to:
if (time.clock() - self.t_on) >= 0.500:
self.t_on =time.clock() - ((time.clock() - self.t_on) - 0.500)