From bfde2e04210e9f8c8e470801ec6cdc668063db59 Mon Sep 17 00:00:00 2001 From: jbruce Date: Tue, 15 Nov 2022 10:46:00 -0500 Subject: [PATCH 1/4] fix ticks to be even hours/mins/secs on graph --- config.py | 2 +- public/assets/js/picoreflow.js | 70 +++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/config.py b/config.py index 77d3736..3909e03 100644 --- a/config.py +++ b/config.py @@ -107,7 +107,7 @@ sim_R_ho_air = 0.05 # K/W " with internal air circulation temp_scale = "f" # c = Celsius | f = Fahrenheit - Unit to display time_scale_slope = "h" # s = Seconds | m = Minutes | h = Hours - Slope displayed in temp_scale per time_scale_slope -time_scale_profile = "m" # s = Seconds | m = Minutes | h = Hours - Enter and view target time in time_scale_profile +time_scale_profile = "h" # s = Seconds | m = Minutes | h = Hours - Enter and view target time in time_scale_profile # emergency shutoff the profile if this temp is reached or exceeded. # This just shuts off the profile. If your SSR is working, your kiln will diff --git a/public/assets/js/picoreflow.js b/public/assets/js/picoreflow.js index 95c6ede..3666579 100644 --- a/public/assets/js/picoreflow.js +++ b/public/assets/js/picoreflow.js @@ -188,23 +188,51 @@ function hazardTemp(){ } } -function timeTickFormatter(val) +function timeTickFormatter(val,axis) { - if (val < 1800) - { - return val; - } - else - { - var hours = Math.floor(val / (3600)); - var div_min = val % (3600); - var minutes = Math.floor(div_min / 60); +console.log(val) - if (hours < 10) {hours = "0"+hours;} - if (minutes < 10) {minutes = "0"+minutes;} +// hours +if(axis.max>3600) { + //var hours = Math.floor(val / (3600)); + //return hours; + return Math.floor(val/3600); + } - return hours+":"+minutes; - } +// minutes +if(axis.max<=3600) { + return Math.floor(val/60); + } + +// seconds +if(axis.max<=60) { + return val; + } + + +//var div_min = val % (3600); +//var minutes = Math.floor(div_min / 60); + + +//if(val < 60) { return "0:00:" + ("00"+val).slice(-3);} +//if(val > 60 and val < 3600) { return "0: + +// if (val < 1800) +// { +// return val; +// } +// else +// { +// var hours = Math.floor(val / (3600)); +// var div_min = val % (3600); +// var minutes = Math.floor(div_min / 60); + +// if (hours < 10) {hours = "0"+hours;} +// if (minutes < 10) {minutes = "0"+minutes;} + + //return hours+":"+minutes; +// return hours+":00"; +// } } function runTask() @@ -366,6 +394,19 @@ function saveProfile() leaveEditMode(); } +function get_tick_size() { +switch(time_scale_profile){ + case "s": + return 1; + case "m": + return 60; + case "h": + return 3600; + } +return 3600; +} + + function getOptions() { @@ -395,6 +436,7 @@ function getOptions() min: 0, tickColor: 'rgba(216, 211, 197, 0.2)', tickFormatter: timeTickFormatter, + tickSize: get_tick_size(), font: { size: 14, From 9b78ea005c9aa7bc48dc68adf694b82dd16e9f9b Mon Sep 17 00:00:00 2001 From: jbruce Date: Tue, 15 Nov 2022 11:02:21 -0500 Subject: [PATCH 2/4] clean up my mess --- public/assets/js/picoreflow.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/public/assets/js/picoreflow.js b/public/assets/js/picoreflow.js index 3666579..7ceb50e 100644 --- a/public/assets/js/picoreflow.js +++ b/public/assets/js/picoreflow.js @@ -190,8 +190,6 @@ function hazardTemp(){ function timeTickFormatter(val,axis) { -console.log(val) - // hours if(axis.max>3600) { //var hours = Math.floor(val / (3600)); @@ -208,31 +206,6 @@ if(axis.max<=3600) { if(axis.max<=60) { return val; } - - -//var div_min = val % (3600); -//var minutes = Math.floor(div_min / 60); - - -//if(val < 60) { return "0:00:" + ("00"+val).slice(-3);} -//if(val > 60 and val < 3600) { return "0: - -// if (val < 1800) -// { -// return val; -// } -// else -// { -// var hours = Math.floor(val / (3600)); -// var div_min = val % (3600); -// var minutes = Math.floor(div_min / 60); - -// if (hours < 10) {hours = "0"+hours;} -// if (minutes < 10) {minutes = "0"+minutes;} - - //return hours+":"+minutes; -// return hours+":00"; -// } } function runTask() @@ -406,7 +379,6 @@ switch(time_scale_profile){ return 3600; } - function getOptions() { From f5336ec2a11bfad2fc3ca4df7cfaf65349e0564d Mon Sep 17 00:00:00 2001 From: James Kirikland Garner Date: Wed, 14 Dec 2022 16:32:10 -0800 Subject: [PATCH 3/4] Speeding up simulator. --- lib/oven.py | 22 +++++++++++++++++++--- lib/ovenWatcher.py | 9 ++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/oven.py b/lib/oven.py index 7503fac..45fd05e 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -243,6 +243,9 @@ class Oven(threading.Thread): self.reset() self.save_automatic_restart_state() + def get_start_time(self): + return datetime.datetime.now() - datetime.timedelta(milliseconds = self.runtime * 1000) + def kiln_must_catch_up(self): '''shift the whole schedule forward in time by one time_step to wait for the kiln to catch up''' @@ -252,11 +255,11 @@ class Oven(threading.Thread): # kiln too cold, wait for it to heat up if self.target - temp > config.pid_control_window: log.info("kiln must catch up, too cold, shifting schedule") - self.start_time = datetime.datetime.now() - datetime.timedelta(milliseconds = self.runtime * 1000) + self.start_time = self.get_start_time() # kiln too hot, wait for it to cool down if temp - self.target > config.pid_control_window: log.info("kiln must catch up, too hot, shifting schedule") - self.start_time = datetime.datetime.now() - datetime.timedelta(milliseconds = self.runtime * 1000) + self.start_time = self.get_start_time() def update_runtime(self): @@ -414,6 +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 # set temps to the temp of the surrounding environment self.t = self.t_env # deg C temp of oven @@ -425,6 +429,18 @@ class SimulatedOven(Oven): self.start() log.info("SimulatedOven started") + # runtime is in sped up time, start_time is actual time of day + def get_start_time(self): + return datetime.datetime.now() - datetime.timedelta(milliseconds = self.runtime * 1000 / self.speedup_factor) + + def update_runtime(self): + + runtime_delta = datetime.datetime.now() - self.start_time + if runtime_delta.total_seconds() < 0: + runtime_delta = datetime.timedelta(0) + + self.runtime = runtime_delta.total_seconds() * self.speedup_factor + def heating_energy(self,pid): # using pid here simulates the element being on for # only part of the time_step @@ -489,7 +505,7 @@ class SimulatedOven(Oven): # we don't actually spend time heating & cooling during # a simulation, so sleep. - time.sleep(self.time_step) + time.sleep(self.time_step / self.speedup_factor) class RealOven(Oven): diff --git a/lib/ovenWatcher.py b/lib/ovenWatcher.py index 3e47e4f..19dd2ad 100644 --- a/lib/ovenWatcher.py +++ b/lib/ovenWatcher.py @@ -1,4 +1,6 @@ import threading,logging,json,time,datetime + +import config from oven import Oven log = logging.getLogger(__name__) @@ -32,7 +34,12 @@ class OvenWatcher(threading.Thread): else: self.recording = False self.notify_all(oven_state) - time.sleep(self.oven.time_step) + + if config.simulate: + time.sleep(self.oven.time_step / self.oven.speedup_factor) + else: + time.sleep(self.oven.time_step) + def lastlog_subset(self,maxpts=50): '''send about maxpts from lastlog by skipping unwanted data''' From 945fcf4187d173ed263b23fb24f6ca3cb38b4566 Mon Sep 17 00:00:00 2001 From: James Kirikland Garner Date: Wed, 14 Dec 2022 19:22:42 -0800 Subject: [PATCH 4/4] 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)