changeset 5:8d471840b153

Support overshooting on heating/cooling.
author darius
date Sat, 29 Sep 2007 02:23:24 +0000
parents 32a56dd33e42
children 45d9895a5020
files beermon.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/beermon.py	Fri Sep 28 13:05:11 2007 +0000
+++ b/beermon.py	Sat Sep 29 02:23:24 2007 +0000
@@ -4,7 +4,7 @@
 # Monitor & control fermenter temperature 
 # v1.0
 #
-# $Id: beermon.py,v 1.5 2007/09/28 13:05:11 darius Exp $
+# $Id: beermon.py,v 1.6 2007/09/29 02:23:24 darius Exp $
 #
 # Depends on: Python 2.3 (I think)
 #
@@ -83,6 +83,7 @@
 
             # Work out what state we should go into
             nextState = "-"
+            # Temperature diff, -ve => too cold, +ve => too warm
             diff = self.m.temps[self.m.fermenterId] - self.targetTemp
             if (self.m.currState == 'idle'):
                 # If we're idle then only heat or cool if the temperate difference is out of the
@@ -93,12 +94,12 @@
                     elif (diff > 0 and self.m.minHeatOffTime + self.m.lastHeatOff < time.time()):
                         nextState = 'cool'
             elif (self.m.currState == 'cool'):
-                # Go idle as soon as we can, there will be overshoot anyway
-                if (diff < 0 and self.m.minCoolOnTime + self.m.lastCoolOn < time.time()):
+                # Work out if we should go idle (based on min on time & overshoot)
+                if (diff + self.m.minCoolOvershoot < 0 and self.m.minCoolOnTime + self.m.lastCoolOn < time.time()):
                     nextState = 'idle'
             elif (self.m.currState == 'heat'):
                 # Ditto
-                if (diff > 0 and self.m.minHeatOnTime + self.m.lastHeatOn < time.time()):
+                if (diff - self.m.minHeatOvershoot > 0 and self.m.minHeatOnTime + self.m.lastHeatOn < time.time()):
                     nextState = 'idle'
             else:
                 # Not possible..
@@ -136,6 +137,10 @@
     minHeatOnTime = 60
     minHeatOffTime = 60
 
+    # minimum to overshoot on heating/cooling
+    minHeatOvershoot = 1
+    minCoolOvershoot = 0
+
     # Dictionary of sensor IDs & temperatures
     temps = {}
     # Dictionary of sensor IDs & epoch times
@@ -330,7 +335,7 @@
     log = initLog()
 
     log.debug("=== Initing ===")
-    log.debug("$Id: beermon.py,v 1.5 2007/09/28 13:05:11 darius Exp $")
+    log.debug("$Id: beermon.py,v 1.6 2007/09/29 02:23:24 darius Exp $")
 
     m = None
     exitCode = 0