diff py/fridge.py @ 271:11cebd6f0bfb

untested fridge.integrator
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Nov 2015 00:20:20 +0800
parents 50a0e2d7d9e3
children af924d27140f
line wrap: on
line diff
--- a/py/fridge.py	Wed Nov 11 00:07:21 2015 +0800
+++ b/py/fridge.py	Wed Nov 11 00:20:20 2015 +0800
@@ -5,6 +5,7 @@
 import config
 
 import gpio
+import utils
 
 class Fridge(object):
 
@@ -13,6 +14,7 @@
     def __init__(self, server, nowait = False):
         self.server = server
         self.gpio = gpio.Gpio(config.FRIDGE_GPIO_PIN, "fridge")
+        self.integrator = utils.StepIntegrator(self.server.now, self.server.params.overshoot_delay)
         self.wort_valid_clock = 0
         self.fridge_on_clock = 0
         self.off()
@@ -21,10 +23,10 @@
 
     def turn(self, value):
         self.gpio.turn(value)
+        self.integrator.turn(value)
 
     def on(self):
         self.turn(True)
-        pass
 
     def off(self):
         self.turn(False)
@@ -61,6 +63,8 @@
         if wort is not None:
             self.wort_valid_clock = self.server.now()
 
+        self.integrator.set_limit(params.overshoot_delay)
+
         # Safety to avoid bad things happening to the fridge motor (?)
         # When it turns off don't start up again for at least FRIDGE_DELAY
         if not self.is_on() and off_time < config.FRIDGE_DELAY:
@@ -90,11 +94,7 @@
             turn_off = False
             on_time = self.server.now() - self.fridge_on_clock
 
-            overshoot = 0
-            if on_time > params.overshoot_delay:
-                overshoot = params.overshoot_factor \
-                    * min(self.OVERSHOOT_MAX_DIV, on_time) \
-                    / self.OVERSHOOT_MAX_DIV
+            overshoot = params.overshoot_factor * self.integrator.integrate()
             D("on_time %(on_time)f, overshoot %(overshoot)f" % locals())
 
             if not params.nowort and wort is not None: