comparison beermon.py @ 7:860936fab75f

Support overshooting on heating/cooling.
author darius
date Sat, 29 Sep 2007 02:23:24 +0000
parents a51f78d44552
children 483375ca5d10
comparison
equal deleted inserted replaced
6:a51f78d44552 7:860936fab75f
2 2
3 ############################################################################ 3 ############################################################################
4 # Monitor & control fermenter temperature 4 # Monitor & control fermenter temperature
5 # v1.0 5 # v1.0
6 # 6 #
7 # $Id: beermon.py,v 1.5 2007/09/28 13:05:11 darius Exp $ 7 # $Id: beermon.py,v 1.6 2007/09/29 02:23:24 darius Exp $
8 # 8 #
9 # Depends on: Python 2.3 (I think) 9 # Depends on: Python 2.3 (I think)
10 # 10 #
11 ############################################################################ 11 ############################################################################
12 # 12 #
81 self.m.setState('idle') 81 self.m.setState('idle')
82 continue 82 continue
83 83
84 # Work out what state we should go into 84 # Work out what state we should go into
85 nextState = "-" 85 nextState = "-"
86 # Temperature diff, -ve => too cold, +ve => too warm
86 diff = self.m.temps[self.m.fermenterId] - self.targetTemp 87 diff = self.m.temps[self.m.fermenterId] - self.targetTemp
87 if (self.m.currState == 'idle'): 88 if (self.m.currState == 'idle'):
88 # If we're idle then only heat or cool if the temperate difference is out of the 89 # If we're idle then only heat or cool if the temperate difference is out of the
89 # hysteresis band 90 # hysteresis band
90 if (abs(diff) > self.hysteresis): 91 if (abs(diff) > self.hysteresis):
91 if (diff < 0 and self.m.minHeatOffTime + self.m.lastHeatOff < time.time()): 92 if (diff < 0 and self.m.minHeatOffTime + self.m.lastHeatOff < time.time()):
92 nextState = 'heat' 93 nextState = 'heat'
93 elif (diff > 0 and self.m.minHeatOffTime + self.m.lastHeatOff < time.time()): 94 elif (diff > 0 and self.m.minHeatOffTime + self.m.lastHeatOff < time.time()):
94 nextState = 'cool' 95 nextState = 'cool'
95 elif (self.m.currState == 'cool'): 96 elif (self.m.currState == 'cool'):
96 # Go idle as soon as we can, there will be overshoot anyway 97 # Work out if we should go idle (based on min on time & overshoot)
97 if (diff < 0 and self.m.minCoolOnTime + self.m.lastCoolOn < time.time()): 98 if (diff + self.m.minCoolOvershoot < 0 and self.m.minCoolOnTime + self.m.lastCoolOn < time.time()):
98 nextState = 'idle' 99 nextState = 'idle'
99 elif (self.m.currState == 'heat'): 100 elif (self.m.currState == 'heat'):
100 # Ditto 101 # Ditto
101 if (diff > 0 and self.m.minHeatOnTime + self.m.lastHeatOn < time.time()): 102 if (diff - self.m.minHeatOvershoot > 0 and self.m.minHeatOnTime + self.m.lastHeatOn < time.time()):
102 nextState = 'idle' 103 nextState = 'idle'
103 else: 104 else:
104 # Not possible.. 105 # Not possible..
105 raise KeyError 106 raise KeyError
106 107
133 minCoolOffTime = 10 * 60 134 minCoolOffTime = 10 * 60
134 135
135 # minimum time the heater must spend on/off 136 # minimum time the heater must spend on/off
136 minHeatOnTime = 60 137 minHeatOnTime = 60
137 minHeatOffTime = 60 138 minHeatOffTime = 60
139
140 # minimum to overshoot on heating/cooling
141 minHeatOvershoot = 1
142 minCoolOvershoot = 0
138 143
139 # Dictionary of sensor IDs & temperatures 144 # Dictionary of sensor IDs & temperatures
140 temps = {} 145 temps = {}
141 # Dictionary of sensor IDs & epoch times 146 # Dictionary of sensor IDs & epoch times
142 lastUpdate = {} 147 lastUpdate = {}
328 333
329 global log 334 global log
330 log = initLog() 335 log = initLog()
331 336
332 log.debug("=== Initing ===") 337 log.debug("=== Initing ===")
333 log.debug("$Id: beermon.py,v 1.5 2007/09/28 13:05:11 darius Exp $") 338 log.debug("$Id: beermon.py,v 1.6 2007/09/29 02:23:24 darius Exp $")
334 339
335 m = None 340 m = None
336 exitCode = 0 341 exitCode = 0
337 try: 342 try:
338 m = beermon.MonitorDev() 343 m = beermon.MonitorDev()