Compare commits

..

No commits in common. "e1fdc86e4093b5ea386bec991c4fa81c87b58a6a" and "8ac4a32106d2c04984a3b4b8c08a1c1eabfb1cf6" have entirely different histories.

3 changed files with 104 additions and 120 deletions

View File

@ -6,11 +6,40 @@ from pyqtgraph.parametertree import (
)
def set_tree_label_tips(tree):
for item in tree.listAllItems():
p = item.param
if "tip" in p.opts:
item.setToolTip(0, p.opts["tip"])
class MutexParameter(pTypes.ListParameter):
"""
Mutually exclusive parameter where only one of its children is visible at a time, list selectable.
The ordering of the list items determines which children will be visible.
"""
def __init__(self, **opts):
super().__init__(**opts)
self.sigValueChanged.connect(self.show_chosen_child)
self.sigValueChanged.emit(self, self.opts["value"])
def _get_param_from_value(self, value):
if isinstance(self.opts["limits"], dict):
values_list = list(self.opts["limits"].values())
else:
values_list = self.opts["limits"]
return self.children()[values_list.index(value)]
@pyqtSlot(object, object)
def show_chosen_child(self, value):
for param in self.children():
param.hide()
child_to_show = self._get_param_from_value(value.value())
child_to_show.show()
if child_to_show.opts.get("triggerOnShow", None):
child_to_show.sigValueChanged.emit(child_to_show, child_to_show.value())
registerParameterType("mutex", MutexParameter)
class CtrlPanel(QObject):
@ -29,40 +58,29 @@ class CtrlPanel(QObject):
self.trees_ui = trees_ui
self.NUM_CHANNELS = len(trees_ui)
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
self.params = [
Parameter.create(
name=f"Thermostat Channel {ch} Parameters",
type="group",
value=ch,
children=param_tree,
children=self.THERMOSTAT_PARAMETERS[ch],
)
for ch in range(self.NUM_CHANNELS)
]
for ch, tree in enumerate(self.trees_ui):
for i, param in enumerate(self.params):
param.channel = i
for i, tree in enumerate(self.trees_ui):
tree.setHeaderHidden(True)
tree.setParameters(self.params[ch], showTop=False)
tree.setParameters(self.params[i], showTop=False)
self.params[i].setValue = self._setValue
self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle)
set_tree_label_tips(tree)
for ch, param in enumerate(self.params):
self.params[ch].setValue = self._setValue
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
for handle in sigActivated_handles[ch]:
param.child(*handle[0]).sigActivated.connect(handle[1])
param.child("output", "control_method").sigValueChanged.connect(
lambda param, value: param.child("i_set").setWritable(
value == "constant_current"
)
)
param.child("output", "control_method").sigValueChanged.connect(
lambda param, value: param.child("target").show(
value == "temperature_pid"
)
)
for handle in sigActivated_handles[i]:
self.params[i].child(*handle[0]).sigActivated.connect(handle[1])
def _setValue(self, value, blockSignal=None):
"""
@ -134,7 +152,7 @@ class CtrlPanel(QObject):
)
if settings["tec_i"] is not None:
self.params[channel].child("tec_i").setValue(
settings["tec_i"]
settings["tec_i"] * 1000
)
@pyqtSlot("QVariantList")

View File

@ -5,30 +5,26 @@
"title": "Temperature",
"type": "float",
"format": "{value:.4f} °C",
"readonly": true,
"tip": "The measured temperature at the thermistor"
"readonly": true
},
{
"name": "tec_i",
"title": "Current through TEC",
"type": "float",
"siPrefix": true,
"suffix": "A",
"suffix": "mA",
"decimals": 6,
"readonly": true,
"tip": "The measured current through the TEC"
"readonly": true
},
{
"name": "output",
"title": "Output Settings",
"expanded": true,
"type": "group",
"tip": "Settings of the output to the TEC",
"children": [
{
"name": "control_method",
"title": "Control Method",
"type": "list",
"type": "mutex",
"limits": {
"Constant Current": "constant_current",
"Temperature PID": "temperature_pid"
@ -41,11 +37,10 @@
"pid"
]
],
"tip": "Select control method of output",
"children": [
{
"name": "i_set",
"title": "Set Current (mA)",
"title": "Set Current",
"type": "float",
"value": 0,
"step": 100,
@ -55,34 +50,30 @@
],
"triggerOnShow": true,
"decimals": 6,
"compactHeight": false,
"suffix": "mA",
"param": [
"pwm",
"ch",
"i_set"
],
"tip": "The set current through TEC",
"lock": false
},
{
"name": "target",
"title": "Setpoint (°C)",
"title": "Set Temperature",
"type": "float",
"visible": false,
"value": 25,
"step": 0.1,
"limits": [
-273,
300
],
"format": "{value:.4f}",
"compactHeight": false,
"format": "{value:.4f} °C",
"param": [
"pid",
"ch",
"target"
],
"tip": "The temperature setpoint of the TEC",
"lock": false
}
]
@ -92,66 +83,62 @@
"title": "Limits",
"expanded": true,
"type": "group",
"tip": "The limits of output, with the polarity at the front panel as reference",
"children": [
{
"name": "max_i_pos",
"title": "Max Cooling Current (mA)",
"title": "Max Cooling Current",
"type": "float",
"value": 0,
"step": 100,
"decimals": 6,
"compactHeight": false,
"limits": [
0,
2000
],
"suffix": "mA",
"param": [
"pwm",
"ch",
"max_i_pos"
],
"tip": "The maximum cooling (+ve) current through the output pins",
"lock": false
},
{
"name": "max_i_neg",
"title": "Max Heating Current (mA)",
"title": "Max Heating Current",
"type": "float",
"value": 0,
"step": 100,
"decimals": 6,
"compactHeight": false,
"limits": [
0,
2000
],
"suffix": "mA",
"param": [
"pwm",
"ch",
"max_i_neg"
],
"tip": "The maximum heating (-ve) current through the output pins",
"lock": false
},
{
"name": "max_v",
"title": "Max Absolute Voltage (V)",
"title": "Max Voltage Difference",
"type": "float",
"value": 0,
"step": 0.1,
"limits": [
0,
4
5
],
"siPrefix": true,
"compactHeight": false,
"suffix": "V",
"param": [
"pwm",
"ch",
"max_v"
],
"tip": "The maximum voltage (in both directions) across the output pins",
"lock": false
}
]
@ -163,11 +150,11 @@
"title": "Thermistor Settings",
"expanded": true,
"type": "group",
"tip": "Settings of the connected thermistor\n- Parameters for the resistance to temperature conversion (with the B-Parameter equation)\n- Settings for the 50/60 Hz filter with the thermistor",
"tip": "Settings of the connected Thermistor",
"children": [
{
"name": "t0",
"title": "T₀ (°C)",
"title": "T₀",
"type": "float",
"value": 25,
"step": 0.1,
@ -175,51 +162,47 @@
-100,
100
],
"format": "{value:.4f}",
"compactHeight": false,
"format": "{value:.4f} °C",
"param": [
"s-h",
"ch",
"t0"
],
"tip": "The base temperature",
"lock": false
},
{
"name": "r0",
"title": "R₀ (Ω)",
"title": "R₀",
"type": "float",
"value": 10000,
"step": 1,
"siPrefix": true,
"compactHeight": false,
"suffix": "Ω",
"param": [
"s-h",
"ch",
"r0"
],
"tip": "The resistance of the thermistor at base temperature T₀",
"lock": false
},
{
"name": "b",
"title": "B (K)",
"title": "B",
"type": "float",
"value": 3950,
"step": 1,
"suffix": "K",
"decimals": 4,
"compactHeight": false,
"param": [
"s-h",
"ch",
"b"
],
"tip": "The Beta Parameter",
"lock": false
},
{
"name": "rate",
"title": "50/60 Hz filter rejection",
"title": "Postfilter Rate",
"type": "list",
"value": 16.67,
"param": [
@ -229,12 +212,11 @@
],
"limits": {
"Off": null,
"47 dB @ 10.41 Hz": 27.0,
"62 dB @ 9.1 Hz": 21.25,
"86 dB @ 10 Hz": 20.0,
"92 dB @ 8.4 Hz": 16.67
"16.67 Hz": 16.67,
"20 Hz": 20.0,
"21.25 Hz": 21.25,
"27 Hz": 27.0
},
"tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz",
"lock": false
}
]
@ -244,7 +226,6 @@
"title": "PID Settings",
"expanded": true,
"type": "group",
"tip": "Settings of PID parameters and clamping",
"children": [
{
"name": "kp",
@ -252,41 +233,37 @@
"type": "float",
"step": 0.1,
"suffix": "",
"compactHeight": false,
"param": [
"pid",
"ch",
"kp"
],
"tip": "Proportional gain",
"lock": false
},
{
"name": "ki",
"title": "Ki (Hz)",
"title": "Ki",
"type": "float",
"step": 0.1,
"compactHeight": false,
"suffix": "Hz",
"param": [
"pid",
"ch",
"ki"
],
"tip": "Integral gain",
"lock": false
},
{
"name": "kd",
"title": "Kd (s)",
"title": "Kd",
"type": "float",
"step": 0.1,
"compactHeight": false,
"suffix": "s",
"param": [
"pid",
"ch",
"kd"
],
"tip": "Differential gain",
"lock": false
},
{
@ -294,11 +271,10 @@
"title": "PID Output Clamping",
"expanded": true,
"type": "group",
"tip": "Clamps PID outputs to specified range\nCould be different than output limits",
"children": [
{
"name": "output_min",
"title": "Minimum (mA)",
"title": "Minimum",
"type": "float",
"step": 100,
"limits": [
@ -306,18 +282,17 @@
2000
],
"decimals": 6,
"compactHeight": false,
"suffix": "mA",
"param": [
"pid",
"ch",
"output_min"
],
"tip": "Minimum PID output",
"lock": false
},
{
"name": "output_max",
"title": "Maximum (mA)",
"title": "Maximum",
"type": "float",
"step": 100,
"limits": [
@ -325,90 +300,81 @@
2000
],
"decimals": 6,
"compactHeight": false,
"suffix": "mA",
"param": [
"pid",
"ch",
"output_max"
],
"tip": "Maximum PID output",
"lock": false
}
]
},
{
"name": "pid_autotune",
"title": "PID Autotune",
"title": "PID Auto Tune",
"expanded": false,
"type": "group",
"tip": "Automatically tune PID parameters",
"children": [
{
"name": "target_temp",
"title": "Target Temperature (°C)",
"title": "Target Temperature",
"type": "float",
"value": 20,
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"format": "{value:.4f} °C",
"pid_autotune": [
"target_temp",
"ch"
],
"tip": "The target temperature to autotune for"
]
},
{
"name": "test_current",
"title": "Test Current (mA)",
"title": "Test Current",
"type": "float",
"value": 0,
"decimals": 6,
"compactHeight": false,
"step": 100,
"limits": [
0,
-2000,
2000
],
"suffix": "mA",
"pid_autotune": [
"test_current",
"ch"
],
"tip": "The testing current when autotuning"
]
},
{
"name": "temp_swing",
"title": "Temperature Swing (°C)",
"title": "Temperature Swing",
"type": "float",
"value": 1.5,
"step": 0.1,
"prefix": "±",
"format": "{value:.4f}",
"compactHeight": false,
"format": "{value:.4f} °C",
"pid_autotune": [
"temp_swing",
"ch"
],
"tip": "The temperature swing around the target"
]
},
{
"name": "lookback",
"title": "Lookback (s)",
"title": "Lookback",
"type": "float",
"value": 3.0,
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"format": "{value:.4f} s",
"pid_autotune": [
"lookback",
"ch"
],
"tip": "Amount of time referenced for tuning"
]
},
{
"name": "run_pid",
"title": "Run",
"type": "action",
"tip": "Run PID Autotune with above settings"
"tip": "Run"
}
]
}
@ -424,7 +390,7 @@
"name": "load",
"title": "Load from flash",
"type": "action",
"tip": "Load settings from thermostat"
"tip": "Load settings from flash"
}
]
}

View File

@ -82,7 +82,7 @@ class MainWindow(QtWidgets.QMainWindow):
[["load"], partial(self.thermostat.load_cfg, ch)],
[
["pid", "pid_autotune", "run_pid"],
partial(self.pid_autotune_request, ch),
partial(self.pid_auto_tune_request, ch),
],
]
for ch in range(self.NUM_CHANNELS)
@ -262,12 +262,12 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(object, object)
async def send_command(self, param, changes):
"""Translates parameter tree changes into thermostat set_param calls"""
ch = param.value()
ch = param.channel
for inner_param, change, data in changes:
if change == "value":
if inner_param.opts.get("param", None) is not None:
if inner_param.opts.get("title", None).endswith(" (mA)"):
if inner_param.opts.get("suffix", None) == "mA":
data /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"]
@ -283,10 +283,10 @@ class MainWindow(QtWidgets.QMainWindow):
param.child(*param.childPath(inner_param)).setOpts(lock=False)
if inner_param.opts.get("pid_autotune", None) is not None:
autotuner_param = inner_param.opts["pid_autotune"][0]
auto_tuner_param = inner_param.opts["pid_autotune"][0]
if inner_param.opts["pid_autotune"][1] != "ch":
ch = inner_param.opts["pid_autotune"][1]
self.autotuners.set_params(autotuner_param, ch, data)
self.autotuners.set_params(auto_tuner_param, ch, data)
if inner_param.opts.get("activaters", None) is not None:
activater = inner_param.opts["activaters"][
@ -298,7 +298,7 @@ class MainWindow(QtWidgets.QMainWindow):
await self.client.set_param(*activater)
@asyncSlot()
async def pid_autotune_request(self, ch=0):
async def pid_auto_tune_request(self, ch=0):
match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
self.autotuners.load_params_and_set_ready(ch)