Skip to content

Commit

Permalink
Add start of ability to modify PID settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hotguac committed Mar 3, 2022
1 parent cbdc59b commit c777d0d
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/*
logs/*.log
logs/*.log*
xchg/*
simple_pid.py
webserver/__pycache__/*
116 changes: 116 additions & 0 deletions bpid.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions cpid.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 17 additions & 3 deletions gui_middle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Import application libraries --------------------------------------
import assign
import beer_temps
import bpid
import cpid
import colors
import paths
import settings
Expand All @@ -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)

Expand All @@ -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, {})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions utils/brewferm-restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion utils/brewferm-shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 0 additions & 2 deletions xchg.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ 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)

x = self.blue_out.read()
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)

Expand Down

0 comments on commit c777d0d

Please sign in to comment.