add recorder code
This commit is contained in:
+16
-14
@@ -26,8 +26,10 @@ class Output(object):
|
||||
log.warning(msg)
|
||||
self.active = False
|
||||
|
||||
def heat(self,sleepfor):
|
||||
def heat(self,sleepfor, tuning=False):
|
||||
self.GPIO.output(config.gpio_heat, self.GPIO.HIGH)
|
||||
if tuning:
|
||||
return
|
||||
time.sleep(sleepfor)
|
||||
self.GPIO.output(config.gpio_heat, self.GPIO.LOW)
|
||||
|
||||
@@ -54,7 +56,7 @@ class Board(object):
|
||||
self.active = True
|
||||
log.info("import %s " % (self.name))
|
||||
except ImportError:
|
||||
msg = "max31855 config set, but import failed"
|
||||
msg = "max31855 config set, but import failed"
|
||||
log.warning(msg)
|
||||
|
||||
if config.max31856:
|
||||
@@ -64,7 +66,7 @@ class Board(object):
|
||||
self.active = True
|
||||
log.info("import %s " % (self.name))
|
||||
except ImportError:
|
||||
msg = "max31856 config set, but import failed"
|
||||
msg = "max31856 config set, but import failed"
|
||||
log.warning(msg)
|
||||
|
||||
def create_temp_sensor(self):
|
||||
@@ -76,7 +78,7 @@ class Board(object):
|
||||
class BoardSimulated(object):
|
||||
def __init__(self):
|
||||
self.temp_sensor = TempSensorSimulated()
|
||||
|
||||
|
||||
class TempSensor(threading.Thread):
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
@@ -118,7 +120,7 @@ class TempSensorReal(TempSensor):
|
||||
'''take 5 measurements over each time period and return the
|
||||
average'''
|
||||
while True:
|
||||
maxtries = 5
|
||||
maxtries = 5
|
||||
sleeptime = self.time_step / float(maxtries)
|
||||
temps = []
|
||||
for x in range(0,maxtries):
|
||||
@@ -245,10 +247,10 @@ class SimulatedOven(Oven):
|
||||
# set temps to the temp of the surrounding environment
|
||||
self.t = self.t_env # deg C temp of oven
|
||||
self.t_h = self.t_env #deg C temp of heating element
|
||||
|
||||
|
||||
# call parent init
|
||||
Oven.__init__(self)
|
||||
|
||||
|
||||
# start thread
|
||||
self.start()
|
||||
log.info("SimulatedOven started")
|
||||
@@ -306,9 +308,9 @@ class SimulatedOven(Oven):
|
||||
self.runtime,
|
||||
self.totaltime,
|
||||
time_left))
|
||||
|
||||
|
||||
# we don't actually spend time heating & cooling during
|
||||
# a simulation, so sleep.
|
||||
# a simulation, so sleep.
|
||||
time.sleep(self.time_step)
|
||||
|
||||
|
||||
@@ -396,7 +398,7 @@ class PID():
|
||||
self.lastErr = 0
|
||||
|
||||
# FIX - this was using a really small window where the PID control
|
||||
# takes effect from -1 to 1. I changed this to various numbers and
|
||||
# takes effect from -1 to 1. I changed this to various numbers and
|
||||
# settled on -50 to 50 and then divide by 50 at the end. This results
|
||||
# in a larger PID control window and much more accurate control...
|
||||
# instead of what used to be binary on/off control.
|
||||
@@ -410,7 +412,7 @@ class PID():
|
||||
|
||||
if self.ki > 0:
|
||||
self.iterm += (error * timeDelta * (1/self.ki))
|
||||
|
||||
|
||||
dErr = (error - self.lastErr) / timeDelta
|
||||
output = self.kp * error + self.iterm + self.kd * dErr
|
||||
out4logs = output
|
||||
@@ -427,10 +429,10 @@ class PID():
|
||||
|
||||
output = float(output / window_size)
|
||||
|
||||
if out4logs > 0:
|
||||
if out4logs > 0:
|
||||
log.info("pid percents pid=%0.2f p=%0.2f i=%0.2f d=%0.2f" % (out4logs,
|
||||
((self.kp * error)/out4logs)*100,
|
||||
((self.kp * error)/out4logs)*100,
|
||||
(self.iterm/out4logs)*100,
|
||||
((self.kd * dErr)/out4logs)*100))
|
||||
((self.kd * dErr)/out4logs)*100))
|
||||
|
||||
return output
|
||||
|
||||
Reference in New Issue
Block a user