From c777d0d50d3cfa99bf6b2c7dde376eac7671ff20 Mon Sep 17 00:00:00 2001 From: Joe Kokosa Date: Thu, 3 Mar 2022 17:38:30 -0500 Subject: [PATCH] Add start of ability to modify PID settings --- .gitignore | 3 +- bpid.py | 116 +++++++++++++++++++++++++++++++++++++ cpid.py | 45 ++++++++++++++ gui_middle.py | 20 ++++++- paths.py | 8 +++ settings.py | 5 +- utils/brewferm-restart.sh | 4 ++ utils/brewferm-shutdown.sh | 6 +- xchg.py | 2 - 9 files changed, 200 insertions(+), 9 deletions(-) create mode 100644 bpid.py create mode 100644 cpid.py diff --git a/.gitignore b/.gitignore index 8800040..aac6e81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__/* -logs/*.log +logs/*.log* xchg/* simple_pid.py +webserver/__pycache__/* \ No newline at end of file diff --git a/bpid.py b/bpid.py new file mode 100644 index 0000000..fc2961d --- /dev/null +++ b/bpid.py @@ -0,0 +1,116 @@ +#!/usr/bin/python3 + +# Import 3rd party libraries ---------------------------------------- +import tkinter as tk +import tkinter.font as font + +# Import standard libraries ----------------------------------------- +# import logging + +# Import application libraries -------------------------------------- +import colors +import paths + +from xchg import XchgData + + +# ------------------------------------------------------------------- +# Associate attached sensors to beer, chamber, or ambient temps +# ------------------------------------------------------------------- +class gBPID(tk.Frame): + def __init__(self, master=None): + super().__init__(master) + self.master = master + + self.create_widgets() + + self.xd = XchgData() # read only for now + + self.visible = False + self.populate_widgets() + + def populate_widgets(self): + self.beer_P['text'] = 'P ' + str(self.master.beer_kp) + + def create_widgets(self): + self.button_font = font.Font(family='TkTextFont', size=-60, weight='bold') + + self.plus_P = tk.Button( + self.master.values_box, + text="+", + command=self.increase_P, + foreground=colors.background, + background=colors.normal50, + borderwidth=0, + highlightthickness=0, + font=self.button_font, + activebackground=colors.normal_button, + highlightbackground=colors.normal_button, + highlightcolor=colors.normal_button, + relief=tk.FLAT + ) + + self.minus_P = tk.Button( + self.master.values_box, + text="-", + command=self.decrease_P, + foreground=colors.background, + background=colors.normal50, + borderwidth=0, + highlightthickness=0, + font=self.button_font, + activebackground=colors.normal_button, + highlightbackground=colors.normal_button, + highlightcolor=colors.normal_button, + relief=tk.FLAT + ) + + self.default_P = tk.Button( + self.master.values_box, + text="@", + command=self.default_P, + foreground=colors.background, + background=colors.normal50, + borderwidth=0, + highlightthickness=0, + font=self.button_font, + activebackground=colors.normal_button, + highlightbackground=colors.normal_button, + highlightcolor=colors.normal_button, + relief=tk.FLAT + ) + + self.beer_P = tk.Label(self.master.values_box, + text="P ?.?", + background=colors.background, + fg=colors.normal50, + font=self.button_font + ) + + def increase_P(self): + self.master.beer_kp += 0.1 + self.populate_widgets() + + def decrease_P(self): + self.master.beer_kp -= 0.1 + self.populate_widgets() + + def default_P(self): + self.master.beer_kp = paths.default_beerP + self.populate_widgets() + + def hide(self): + self.visible = False + self.plus_P.place(x=0, y=0, height=0, width=0) + self.minus_P.place(x=0, y=0, height=0, width=0) + self.beer_P.place(x=0, y=0, height=0, width=0) + self.default_P.place(x=0, y=0, height=0, width=0) + + def show(self): + self.visible = True + self.populate_widgets() + + self.plus_P.place(x=160, y=60, height=80, width=80) + self.minus_P.place(x=260, y=60, height=80, width=80) + self.beer_P.place(x=360, y=60, height=80, width=240) + self.default_P.place(x=700, y=60, height=80, width=80) diff --git a/cpid.py b/cpid.py new file mode 100644 index 0000000..d1c01da --- /dev/null +++ b/cpid.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +# Import 3rd party libraries ---------------------------------------- +import tkinter as tk +import tkinter.font as font + +# Import standard libraries ----------------------------------------- +import logging + +# Import application libraries -------------------------------------- +# import colors +# import paths + +from xchg import XchgData + + +# ------------------------------------------------------------------- +# Associate attached sensors to beer, chamber, or ambient temps +# ------------------------------------------------------------------- +class gCPID(tk.Frame): + def __init__(self, master=None): + super().__init__(master) + self.master = master + + self.create_widgets() + + self.xd = XchgData() # read only for now + + self.visible = False + self.populate_widgets() + + def populate_widgets(self): + logging.debug("populate_widgets") + + def create_widgets(self): + normal_font = font.Font(family='DejaVu Sans Mono', size=-36) # , weight='bold') + + def hide(self): + logging.debug("gPBID hide") + self.visible = False + + def show(self): + self.visible = True + self.populate_widgets() + logging.debug("gBIPD show") diff --git a/gui_middle.py b/gui_middle.py index 76fbc25..55e04ad 100644 --- a/gui_middle.py +++ b/gui_middle.py @@ -10,6 +10,8 @@ # Import application libraries -------------------------------------- import assign import beer_temps +import bpid +import cpid import colors import paths import settings @@ -28,6 +30,8 @@ def __init__(self, master=None): self.btemps = None # will hold a gBeerTemps object self.menu = None # will hold a gMenu object self.sensor_assign = None # will hold a gAssign object + self.bpid_settings = None # will hold a gBPID object + self.cpid_settings = None # will hold a gCPID object self.xd = XchgData(paths.gui_out) @@ -39,9 +43,9 @@ def __init__(self, master=None): btuning = self.xd.get(paths.beerPID, {}) - self.beer_kp = btuning.get('kp', 8.0) - self.beer_ki = btuning.get('ki', 0.0015) # 0.0001 - self.beer_kd = btuning.get('kd', 0.0) + self.beer_kp = btuning.get('kp', paths.default_beerP) # 8.0) + self.beer_ki = btuning.get('ki', paths.default_beerI) # 0.0015) # 0.0001 + self.beer_kd = btuning.get('kd', paths.default_beerI) # 0.0) self.beer_sample_time = btuning.get('sample_time', 60) ctuning = self.xd.get(paths.chamberPID, {}) @@ -174,6 +178,12 @@ def update_out(self): if self.sensor_assign is None: self.sensor_assign = assign.gAssign(master=self) + if self.bpid_settings is None: + self.bpid_settings = bpid.gBPID(master=self) + + if self.cpid_settings is None: + self.cpid_settings = cpid.gCPID(master=self) + self.xd.write_gui(self.format_state()) except Exception as e: logging.exception('%s %s', type(e), e) @@ -239,8 +249,12 @@ def settings(self): else: if self.settings_button['text'] == paths.action_back: self.settings_button['text'] = paths.action_settings + self.menu.hide() self.sensor_assign.hide() + self.bpid_settings.hide() + self.cpid_settings.hide() + self.btemps.show_beer() except Exception as e: diff --git a/paths.py b/paths.py index 9309fa5..aa3e9d6 100644 --- a/paths.py +++ b/paths.py @@ -45,3 +45,11 @@ desired_ts = 'desired_ts' sensors_raw = 'sensors_raw' + +default_beerP = 8.0 +default_beerI = 0.0015 +default_beerD = 0 + +default_chamberP = 8.0 +default_chamberI = 0.0015 +default_chamberD = 0 diff --git a/settings.py b/settings.py index 3d410cc..6dedb43 100644 --- a/settings.py +++ b/settings.py @@ -101,12 +101,13 @@ def assign_sensors(self): self.master.sensor_assign.show() def set_beer_pid(self): + logging.debug('in set beer pid') self.hide() - self.master.btemps.show_target() + self.master.bpid_settings.show() def set_chamber_pid(self): self.hide() - self.master.btemps.show_target() + self.master.cpid_settings.show() def hide(self): self.target.place(x=0, y=0, height=0, width=0) diff --git a/utils/brewferm-restart.sh b/utils/brewferm-restart.sh index a37d0ba..8c04af9 100755 --- a/utils/brewferm-restart.sh +++ b/utils/brewferm-restart.sh @@ -5,3 +5,7 @@ sleep 10 sudo systemctl start brewferm-controller.service sleep 20 sudo systemctl start brewferm-relays.service +sleep 10 +sudo systemctl start brewferm-blues.service +sleep 10 +sudo systemctl start brewferm-webs.service diff --git a/utils/brewferm-shutdown.sh b/utils/brewferm-shutdown.sh index 6b748f9..19131e8 100755 --- a/utils/brewferm-shutdown.sh +++ b/utils/brewferm-shutdown.sh @@ -5,4 +5,8 @@ sudo systemctl kill brewferm-sensors.service sudo systemctl stop brewferm-relays.service sudo systemctl kill brewferm-relays.service sudo systemctl stop brewferm-gui.service -sudo systemctl kill brewferm-gui.service \ No newline at end of file +sudo systemctl kill brewferm-gui.service +sudo systemctl stop brewferm-blues.service +sudo systemctl kill brewferm-blues.service +sudo systemctl stop brewferm-webs.service +sudo systemctl kill brewferm-webs.service \ No newline at end of file diff --git a/xchg.py b/xchg.py index 8d2ac92..c1464a1 100644 --- a/xchg.py +++ b/xchg.py @@ -81,7 +81,6 @@ def get(self, field_name, default=None): def get_blue(self): try: - # TODO if self.blue_out is None: self.blue_out = Xchg(paths.blue_out, self.blue_mode) @@ -89,7 +88,6 @@ def get_blue(self): result = None if 'sg' in x.keys(): result = x['sg'] - logging.debug('TODO get_blue') except Exception as e: logging.exception('%s %s', type(e), e)