From 00ed33b0028ea1410e29c60aa344193fe6a406c8 Mon Sep 17 00:00:00 2001 From: sbman Date: Thu, 2 Jul 2015 10:47:34 -0700 Subject: [PATCH] Added non responsive sensor emergency stop Added an 'emergency stop' feature to stop a run if the temperature sensor is no longer providing data. If the temperature sensor values are remaining stable and exactly the same for 20 time cycles consecutively while the heat is on, the run is reset to prevent damage to the part or the oven. --- lib/oven.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/oven.py b/lib/oven.py index 24c010f..a294a99 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -86,6 +86,8 @@ class Oven (threading.Thread): self.reset() def run(self): + temperature_count = 0 + last_temp = 0 while True: self.door = self.get_door_state() @@ -102,8 +104,24 @@ class Oven (threading.Thread): log.info("pid: %.3f" % pid) self.set_cool(pid <= -1) + if(pid > 0): + # The temp should be changing with the heat on + # Count the number of time_steps encountered with no change and the heat on + if last_temp == self.temp_sensor.temperature: + temperature_count += 1 + else: + temperature_count = 0 + # If the heat is on and nothing is changing, reset + # The direction or amount of change does not matter + # This prevents runaway in the event of a sensor read failure + if temperature_count > 20: + log.info("Error reading sensor, oven temp not responding to heat.") + self.reset() + else: + temperature_count = 0 + self.set_heat(pid > 0) - + #if self.profile.is_rising(self.runtime): # self.set_cool(False) # self.set_heat(self.temp_sensor.temperature < self.target) @@ -119,6 +137,9 @@ class Oven (threading.Thread): if self.runtime >= self.totaltime: self.reset() + #Capture the last temperature value + last_temp = self.temp_sensor.temperature + time.sleep(self.time_step) def set_heat(self, value):