implement rudimentary duty-cycle support

master^2
James Gao 2015-02-22 13:03:48 -08:00
rodzic b6ae241f08
commit 67e53d1981
1 zmienionych plików z 13 dodań i 4 usunięć

Wyświetl plik

@ -127,6 +127,7 @@ class Profile(threading.Thread):
self.pid = PID.PID(Kp, Ki, Kd)
self.callback = callback
self.running = True
self.duty_cycle = False
self.start()
@property
@ -157,11 +158,19 @@ class Profile(threading.Thread):
temp = self.therm.temperature.temp
if temp == -1:
continue #skip invalid temperature readings
elif temp - setpoint > 50:
self.regulator.off()
self.duty_cycle = True
pid_out = self.pid.update(temp)
if pid_out < 0: pid_out = 0
if pid_out > 1: pid_out = 1
self.regulator.set(pid_out)
else:
if self.duty_cycle:
self.regulator.ignite()
self.duty_cycle = False
pid_out = self.pid.update(temp)
if pid_out < 0: pid_out = 0
if pid_out > 1: pid_out = 1
self.regulator.set(pid_out)
if self.callback is not None:
self.callback(temp, setpoint, pid_out)