From 3cb20a019bac21137b092c4e54dee10309669e65 Mon Sep 17 00:00:00 2001 From: James Gao Date: Sat, 18 Oct 2014 20:38:43 +0000 Subject: [PATCH] Update from actual testing --- kiln/bisque_firing_06.py | 5 ++++- kiln/manager.py | 7 +++---- kiln/stepper.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/kiln/bisque_firing_06.py b/kiln/bisque_firing_06.py index 2765d7b..81219fc 100644 --- a/kiln/bisque_firing_06.py +++ b/kiln/bisque_firing_06.py @@ -1,6 +1,7 @@ import manager import thermo import sys +import time if __name__ == "__main__": start_time = None @@ -9,6 +10,8 @@ schedule = [[2*60*60, 176], [4*60*60, 620], [6*60*60, 1013], [6*60*60+20*60, 1013]] mon = thermo.Monitor() mon.start() + time.sleep(1) #schedule = [[20, 176], [40, 620], [60, 1013]] kiln = manager.KilnController(schedule, mon, start_time=start_time, simulate=False) - kiln.run() \ No newline at end of file + kiln.run() + mon.stop() diff --git a/kiln/manager.py b/kiln/manager.py index c507f9c..ab275b2 100644 --- a/kiln/manager.py +++ b/kiln/manager.py @@ -17,7 +17,7 @@ def __init__(self, schedule, monitor, interval=5, start_time=None, Kp=.01, Ki=.0 if simulate: self.schedule.insert(0, [0, 15]) else: - self.schedule.insert(0, [0, self.monitor.temperature]) + self.schedule.insert(0, [0, 15]) @property def elapsed(self): @@ -34,13 +34,12 @@ def run(self): #find epoch for i in range(len(self.schedule)-1): if self.schedule[i][0] < ts < self.schedule[i+1][0]: - print "In epoch %d"%i time0, temp0 = self.schedule[i] time1, temp1 = self.schedule[i+1] frac = (ts - time0) / (time1 - time0) setpoint = frac * (temp1 - temp0) + temp0 self.pid.setPoint(setpoint) - + print "In epoch %d, elapsed time %f, temperature %f"%(i, ts, setpoint) if self.simulate: temp = setpoint + random.gauss(-20, 15) else: @@ -49,7 +48,7 @@ def run(self): 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) + self.regulator.set(pid_out, block=True) time.sleep(self.interval - (time.time()-now)) except: diff --git a/kiln/stepper.py b/kiln/stepper.py index 33dc52e..f6ccd14 100644 --- a/kiln/stepper.py +++ b/kiln/stepper.py @@ -16,7 +16,7 @@ class Stepper(threading.Thread): [0,0,1,1], [1,0,0,1]] - def __init__(self, pin1=5, pin2=6, pin3=13, pin4=19, timeout=5): + def __init__(self, pin1=5, pin2=6, pin3=13, pin4=19, timeout=1): self.queue = Queue.Queue() self.finished = threading.Event() @@ -137,7 +137,7 @@ def stop(self): class Regulator(object): - def __init__(self, maxsteps=4500, minsteps=2400, speed=150, ignite_pin=None, simulate=False): + def __init__(self, maxsteps=4500, minsteps=2480, speed=150, ignite_pin=None, simulate=False): """Set up a stepper-controlled regulator. Implement some safety measures to make sure everything gets shut off at the end @@ -180,7 +180,7 @@ def ignite(self, start=2800, delay=1): time.sleep(delay) if self.ignite_pin is not None: GPIO.output(self.ignite_pin, False) - self.stepper.step(self.min - start, self.speed) + self.stepper.step(self.min - start, self.speed, block=True) self.current = self.min print "Done!"