comparison 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
comparison
equal deleted inserted replaced
270:9d0313b685ae 271:11cebd6f0bfb
3 3
4 from utils import L,W,E,EX,D 4 from utils import L,W,E,EX,D
5 import config 5 import config
6 6
7 import gpio 7 import gpio
8 import utils
8 9
9 class Fridge(object): 10 class Fridge(object):
10 11
11 OVERSHOOT_MAX_DIV = 1800.0 # 30 mins 12 OVERSHOOT_MAX_DIV = 1800.0 # 30 mins
12 13
13 def __init__(self, server, nowait = False): 14 def __init__(self, server, nowait = False):
14 self.server = server 15 self.server = server
15 self.gpio = gpio.Gpio(config.FRIDGE_GPIO_PIN, "fridge") 16 self.gpio = gpio.Gpio(config.FRIDGE_GPIO_PIN, "fridge")
17 self.integrator = utils.StepIntegrator(self.server.now, self.server.params.overshoot_delay)
16 self.wort_valid_clock = 0 18 self.wort_valid_clock = 0
17 self.fridge_on_clock = 0 19 self.fridge_on_clock = 0
18 self.off() 20 self.off()
19 if nowait: 21 if nowait:
20 self.fridge_off_clock = 0 22 self.fridge_off_clock = 0
21 23
22 def turn(self, value): 24 def turn(self, value):
23 self.gpio.turn(value) 25 self.gpio.turn(value)
26 self.integrator.turn(value)
24 27
25 def on(self): 28 def on(self):
26 self.turn(True) 29 self.turn(True)
27 pass
28 30
29 def off(self): 31 def off(self):
30 self.turn(False) 32 self.turn(False)
31 self.fridge_off_clock = self.server.now() 33 self.fridge_off_clock = self.server.now()
32 34
59 off_time = self.server.now() - self.fridge_off_clock 61 off_time = self.server.now() - self.fridge_off_clock
60 62
61 if wort is not None: 63 if wort is not None:
62 self.wort_valid_clock = self.server.now() 64 self.wort_valid_clock = self.server.now()
63 65
66 self.integrator.set_limit(params.overshoot_delay)
67
64 # Safety to avoid bad things happening to the fridge motor (?) 68 # Safety to avoid bad things happening to the fridge motor (?)
65 # When it turns off don't start up again for at least FRIDGE_DELAY 69 # When it turns off don't start up again for at least FRIDGE_DELAY
66 if not self.is_on() and off_time < config.FRIDGE_DELAY: 70 if not self.is_on() and off_time < config.FRIDGE_DELAY:
67 L("fridge skipping, too early") 71 L("fridge skipping, too early")
68 return 72 return
88 92
89 if self.is_on(): 93 if self.is_on():
90 turn_off = False 94 turn_off = False
91 on_time = self.server.now() - self.fridge_on_clock 95 on_time = self.server.now() - self.fridge_on_clock
92 96
93 overshoot = 0 97 overshoot = params.overshoot_factor * self.integrator.integrate()
94 if on_time > params.overshoot_delay:
95 overshoot = params.overshoot_factor \
96 * min(self.OVERSHOOT_MAX_DIV, on_time) \
97 / self.OVERSHOOT_MAX_DIV
98 D("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) 98 D("on_time %(on_time)f, overshoot %(overshoot)f" % locals())
99 99
100 if not params.nowort and wort is not None: 100 if not params.nowort and wort is not None:
101 if wort - overshoot < params.fridge_setpoint: 101 if wort - overshoot < params.fridge_setpoint:
102 max_div = self.OVERSHOOT_MAX_DIV 102 max_div = self.OVERSHOOT_MAX_DIV