forked from jcsombria/py-ripserver
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Periodic Sampler to samplers
- Loading branch information
Showing
3 changed files
with
39 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
''' | ||
@author: jcsombria | ||
''' | ||
import time | ||
|
||
class PeriodicSampler(object): | ||
|
||
def __init__(self, period): | ||
# Set the sampling period | ||
self.Ts = period | ||
self.reset() | ||
|
||
def wait(self): | ||
# Wait until the next sampling time | ||
self.last = self.time | ||
self.time = time.time() - self.t0 | ||
self.next = self.time / self.Ts + self.Ts | ||
interval = self.Ts - self.time % self.Ts | ||
time.sleep(interval) | ||
|
||
def reset(self): | ||
# Reset to the initial state | ||
self.t0 = time.time() | ||
self.time = 0 | ||
self.last = 0 | ||
self.next = self.Ts | ||
|
||
def delta(self): | ||
# Compute the time elapsed since the last sampling time | ||
return self.time - self.last | ||
|
||
def lastTime(self): | ||
# Last sampling time | ||
return self.last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .Samplers import PeriodicSampler as Periodic |