Works at 1000 times speed, a little messy.

pull/123/head
James Kirikland Garner 2022-12-14 19:22:42 -08:00
rodzic f5336ec2a1
commit 945fcf4187
4 zmienionych plików z 10 dodań i 7 usunięć

1
.gitignore vendored
Wyświetl plik

@ -8,3 +8,4 @@ thumbs.db
#storage/profiles
#config.py
.idea/*
state.json

Wyświetl plik

@ -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'))

Wyświetl plik

@ -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

Wyświetl plik

@ -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)