From 945fcf4187d173ed263b23fb24f6ca3cb38b4566 Mon Sep 17 00:00:00 2001 From: James Kirikland Garner Date: Wed, 14 Dec 2022 19:22:42 -0800 Subject: [PATCH] Works at 1000 times speed, a little messy. --- .gitignore | 1 + config.py | 2 +- lib/oven.py | 12 +++++++----- lib/ovenWatcher.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 35300ae..d17affe 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ thumbs.db #storage/profiles #config.py .idea/* +state.json diff --git a/config.py b/config.py index 3909e03..2dbed17 100644 --- a/config.py +++ b/config.py @@ -175,7 +175,7 @@ ignore_tc_short_errors = False # cleaned up (deleted) by the OS on boot. # The state file is written to disk every sensor_time_wait seconds (2s by default) # and is written in the same directory as config.py. -automatic_restarts = True +automatic_restarts = False automatic_restart_window = 15 # max minutes since power outage automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'state.json')) diff --git a/lib/oven.py b/lib/oven.py index 45fd05e..8a08b9c 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -417,7 +417,7 @@ class SimulatedOven(Oven): self.R_o_nocool = config.sim_R_o_nocool self.R_ho_noair = config.sim_R_ho_noair self.R_ho = self.R_ho_noair - self.speedup_factor = 10 + self.speedup_factor = 1000 # set temps to the temp of the surrounding environment self.t = self.t_env # deg C temp of oven @@ -441,6 +441,9 @@ class SimulatedOven(Oven): self.runtime = runtime_delta.total_seconds() * self.speedup_factor + def update_target_temp(self): + self.target = self.profile.get_target_temperature(self.runtime) + def heating_energy(self,pid): # using pid here simulates the element being on for # only part of the time_step @@ -466,7 +469,7 @@ class SimulatedOven(Oven): def heat_then_cool(self): pid = self.pid.compute(self.target, self.board.temp_sensor.temperature + - config.thermocouple_offset) + config.thermocouple_offset, self.start_time + datetime.timedelta(milliseconds = self.runtime * 1000)) heat_on = float(self.time_step * pid) heat_off = float(self.time_step * (1 - pid)) @@ -528,7 +531,7 @@ class RealOven(Oven): def heat_then_cool(self): pid = self.pid.compute(self.target, self.board.temp_sensor.temperature + - config.thermocouple_offset) + config.thermocouple_offset, datetime.datetime.now()) heat_on = float(self.time_step * pid) heat_off = float(self.time_step * (1 - pid)) @@ -610,8 +613,7 @@ class PID(): # 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. - def compute(self, setpoint, ispoint): - now = datetime.datetime.now() + def compute(self, setpoint, ispoint, now): timeDelta = (now - self.lastNow).total_seconds() window_size = 100 diff --git a/lib/ovenWatcher.py b/lib/ovenWatcher.py index 19dd2ad..be13146 100644 --- a/lib/ovenWatcher.py +++ b/lib/ovenWatcher.py @@ -36,7 +36,7 @@ class OvenWatcher(threading.Thread): self.notify_all(oven_state) if config.simulate: - time.sleep(self.oven.time_step / self.oven.speedup_factor) + time.sleep(self.oven.time_step) else: time.sleep(self.oven.time_step)