kopia lustrzana https://github.com/jamesgao/kiln_controller
Better timing for PID loop
rodzic
23f2cbc9a4
commit
6f927fd34a
|
@ -143,8 +143,8 @@ class Profile(threading.Thread):
|
|||
self.running = False
|
||||
|
||||
def run(self):
|
||||
_next = time.time()+self.interval
|
||||
while not self.completed and self.running:
|
||||
now = time.time()
|
||||
ts = self.elapsed
|
||||
#find epoch
|
||||
for i in range(len(self.schedule)-1):
|
||||
|
@ -154,18 +154,19 @@ class Profile(threading.Thread):
|
|||
frac = (ts - time0) / (time1 - time0)
|
||||
setpoint = frac * (temp1 - temp0) + temp0
|
||||
self.pid.setPoint(setpoint)
|
||||
|
||||
pid_out = -1
|
||||
|
||||
temp = self.therm.temperature.temp
|
||||
if temp == -1:
|
||||
continue #skip invalid temperature readings
|
||||
elif temp - setpoint > 20:
|
||||
elif temp - setpoint > 10:
|
||||
self.regulator.off()
|
||||
self.duty_cycle = True
|
||||
pid_out = -1
|
||||
elif self.duty_cycle:
|
||||
if temp - setpoint < -10:
|
||||
if temp - setpoint < -5:
|
||||
self.regulator.ignite()
|
||||
self.duty_cycle = False
|
||||
pid_out = -1
|
||||
else:
|
||||
pid_out = self.pid.update(temp)
|
||||
if pid_out < 0: pid_out = 0
|
||||
|
@ -175,4 +176,7 @@ class Profile(threading.Thread):
|
|||
if self.callback is not None:
|
||||
self.callback(temp, setpoint, pid_out)
|
||||
|
||||
time.sleep(self.interval - (time.time()-now))
|
||||
sleep = _next - time.time()
|
||||
if (sleep > 0)
|
||||
time.sleep(sleep)
|
||||
_next += self.interval
|
||||
|
|
Ładowanie…
Reference in New Issue