Files
HendiControlFirmware/Control/brewpi/utils.py
T
jens 69a175beac - reworked
git-svn-id: http://moon:8086/svn/projects/HendiControl@113 fda53097-d464-4ada-af97-ba876c37ca34
2019-03-20 21:11:09 +00:00

30 lines
536 B
Python

class Smoother:
def __init__(self, alpha):
self.a = alpha
self.b = 1-alpha
self.y = 0
def process(self, x):
self.y = self.b*self.y + self.a*x
def get_y(self):
return self.y
class Stable:
def __init__(self, stable_count, err_max):
self.stable_time = stable_count
self.count = stable_count
self.err_max = err_max
self.x = 0
def process(self, x):
if self.count > 0:
self.count -= 1
if abs(x - self.x) >= self.err_max:
self.count = self.stable_time
is_stable = (self.count == 0)
return is_stable