Works at 1000 times speed, a little messy.
This commit is contained in:
parent
f5336ec2a1
commit
945fcf4187
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ thumbs.db
|
|||||||
#storage/profiles
|
#storage/profiles
|
||||||
#config.py
|
#config.py
|
||||||
.idea/*
|
.idea/*
|
||||||
|
state.json
|
||||||
|
|||||||
@ -175,7 +175,7 @@ ignore_tc_short_errors = False
|
|||||||
# cleaned up (deleted) by the OS on boot.
|
# cleaned up (deleted) by the OS on boot.
|
||||||
# The state file is written to disk every sensor_time_wait seconds (2s by default)
|
# 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.
|
# 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_window = 15 # max minutes since power outage
|
||||||
automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'state.json'))
|
automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'state.json'))
|
||||||
|
|
||||||
|
|||||||
12
lib/oven.py
12
lib/oven.py
@ -417,7 +417,7 @@ class SimulatedOven(Oven):
|
|||||||
self.R_o_nocool = config.sim_R_o_nocool
|
self.R_o_nocool = config.sim_R_o_nocool
|
||||||
self.R_ho_noair = config.sim_R_ho_noair
|
self.R_ho_noair = config.sim_R_ho_noair
|
||||||
self.R_ho = self.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
|
# set temps to the temp of the surrounding environment
|
||||||
self.t = self.t_env # deg C temp of oven
|
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
|
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):
|
def heating_energy(self,pid):
|
||||||
# using pid here simulates the element being on for
|
# using pid here simulates the element being on for
|
||||||
# only part of the time_step
|
# only part of the time_step
|
||||||
@ -466,7 +469,7 @@ class SimulatedOven(Oven):
|
|||||||
def heat_then_cool(self):
|
def heat_then_cool(self):
|
||||||
pid = self.pid.compute(self.target,
|
pid = self.pid.compute(self.target,
|
||||||
self.board.temp_sensor.temperature +
|
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_on = float(self.time_step * pid)
|
||||||
heat_off = float(self.time_step * (1 - pid))
|
heat_off = float(self.time_step * (1 - pid))
|
||||||
|
|
||||||
@ -528,7 +531,7 @@ class RealOven(Oven):
|
|||||||
def heat_then_cool(self):
|
def heat_then_cool(self):
|
||||||
pid = self.pid.compute(self.target,
|
pid = self.pid.compute(self.target,
|
||||||
self.board.temp_sensor.temperature +
|
self.board.temp_sensor.temperature +
|
||||||
config.thermocouple_offset)
|
config.thermocouple_offset, datetime.datetime.now())
|
||||||
heat_on = float(self.time_step * pid)
|
heat_on = float(self.time_step * pid)
|
||||||
heat_off = float(self.time_step * (1 - 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
|
# 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...
|
# in a larger PID control window and much more accurate control...
|
||||||
# instead of what used to be binary on/off control.
|
# instead of what used to be binary on/off control.
|
||||||
def compute(self, setpoint, ispoint):
|
def compute(self, setpoint, ispoint, now):
|
||||||
now = datetime.datetime.now()
|
|
||||||
timeDelta = (now - self.lastNow).total_seconds()
|
timeDelta = (now - self.lastNow).total_seconds()
|
||||||
|
|
||||||
window_size = 100
|
window_size = 100
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class OvenWatcher(threading.Thread):
|
|||||||
self.notify_all(oven_state)
|
self.notify_all(oven_state)
|
||||||
|
|
||||||
if config.simulate:
|
if config.simulate:
|
||||||
time.sleep(self.oven.time_step / self.oven.speedup_factor)
|
time.sleep(self.oven.time_step)
|
||||||
else:
|
else:
|
||||||
time.sleep(self.oven.time_step)
|
time.sleep(self.oven.time_step)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user