Compare commits

..

No commits in common. "6dcd1b6275059932f38f2b63bc5705eca26c02f4" and "405d40c543f3c8412b9dec5bcc1891ea12875ea1" have entirely different histories.

3 changed files with 170 additions and 122 deletions

View File

@ -6,6 +6,42 @@ from pyqtgraph.parametertree import (
) )
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)
def set_tree_label_tips(tree): def set_tree_label_tips(tree):
for item in tree.listAllItems(): for item in tree.listAllItems():
p = item.param p = item.param
@ -29,40 +65,28 @@ class CtrlPanel(QObject):
self.trees_ui = trees_ui self.trees_ui = trees_ui
self.NUM_CHANNELS = len(trees_ui) self.NUM_CHANNELS = len(trees_ui)
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
self.params = [ self.params = [
Parameter.create( Parameter.create(
name=f"Thermostat Channel {ch} Parameters", name=f"Thermostat Channel {ch} Parameters",
type="group", type="group",
value=ch, value=ch,
children=param_tree, children=self.THERMOSTAT_PARAMETERS[ch],
) )
for ch in range(self.NUM_CHANNELS) for ch in range(self.NUM_CHANNELS)
] ]
for ch, tree in enumerate(self.trees_ui): for i, tree in enumerate(self.trees_ui):
tree.setHeaderHidden(True) 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) set_tree_label_tips(tree)
for ch, param in enumerate(self.params): for handle in sigActivated_handles[i]:
self.params[ch].setValue = self._setValue self.params[i].child(*handle[0]).sigActivated.connect(handle[1])
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"
)
)
def _setValue(self, value, blockSignal=None): def _setValue(self, value, blockSignal=None):
""" """

View File

@ -28,15 +28,19 @@
{ {
"name": "control_method", "name": "control_method",
"title": "Control Method", "title": "Control Method",
"type": "list", "type": "mutex",
"limits": { "limits": {
"Constant Current": "constant_current", "Constant Current": "constant_current",
"Temperature PID": "temperature_pid" "Temperature PID": "temperature_pid"
}, },
"thermostat:set_param": { "activaters": [
"topic": "pwm", null,
"field": "pid" [
}, "pwm",
"ch",
"pid"
]
],
"tip": "Select control method of output", "tip": "Select control method of output",
"children": [ "children": [
{ {
@ -52,10 +56,11 @@
"triggerOnShow": true, "triggerOnShow": true,
"decimals": 6, "decimals": 6,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pwm", "pwm",
"field": "i_set" "ch",
}, "i_set"
],
"tip": "The set current through TEC", "tip": "The set current through TEC",
"lock": false "lock": false
}, },
@ -63,7 +68,6 @@
"name": "target", "name": "target",
"title": "Set Temperature (°C)", "title": "Set Temperature (°C)",
"type": "float", "type": "float",
"visible": false,
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
"limits": [ "limits": [
@ -72,10 +76,11 @@
], ],
"format": "{value:.4f}", "format": "{value:.4f}",
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "target" "ch",
}, "target"
],
"tip": "The target temperature of the TEC", "tip": "The target temperature of the TEC",
"lock": false "lock": false
} }
@ -100,10 +105,11 @@
0, 0,
2000 2000
], ],
"thermostat:set_param": { "param": [
"topic": "pwm", "pwm",
"field": "max_i_pos" "ch",
}, "max_i_pos"
],
"tip": "The maximum cooling (+ve) current through the output pins", "tip": "The maximum cooling (+ve) current through the output pins",
"lock": false "lock": false
}, },
@ -119,10 +125,11 @@
0, 0,
2000 2000
], ],
"thermostat:set_param": { "param": [
"topic": "pwm", "pwm",
"field": "max_i_neg" "ch",
}, "max_i_neg"
],
"tip": "The maximum heating (-ve) current through the output pins", "tip": "The maximum heating (-ve) current through the output pins",
"lock": false "lock": false
}, },
@ -138,10 +145,11 @@
], ],
"siPrefix": true, "siPrefix": true,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pwm", "pwm",
"field": "max_v" "ch",
}, "max_v"
],
"tip": "The maximum voltage across the output pins", "tip": "The maximum voltage across the output pins",
"lock": false "lock": false
} }
@ -168,10 +176,11 @@
], ],
"format": "{value:.4f}", "format": "{value:.4f}",
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "s-h", "s-h",
"field": "t0" "ch",
}, "t0"
],
"tip": "The origin temperature", "tip": "The origin temperature",
"lock": false "lock": false
}, },
@ -183,10 +192,11 @@
"step": 1, "step": 1,
"siPrefix": true, "siPrefix": true,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "s-h", "s-h",
"field": "r0" "ch",
}, "r0"
],
"tip": "The resistance of the thermistor at origin temperature T₀", "tip": "The resistance of the thermistor at origin temperature T₀",
"lock": false "lock": false
}, },
@ -198,10 +208,11 @@
"step": 1, "step": 1,
"decimals": 4, "decimals": 4,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "s-h", "s-h",
"field": "b" "ch",
}, "b"
],
"tip": "The B (or Beta) Parameter", "tip": "The B (or Beta) Parameter",
"lock": false "lock": false
}, },
@ -210,12 +221,13 @@
"title": "Postfilter Rejection", "title": "Postfilter Rejection",
"type": "list", "type": "list",
"value": 16.67, "value": 16.67,
"thermostat:set_param": { "param": [
"topic": "postfilter", "postfilter",
"field": "rate" "ch",
}, "rate"
],
"limits": { "limits": {
"Off": "", "Off": null,
"47 dB @ 10.41 Hz": 27.0, "47 dB @ 10.41 Hz": 27.0,
"62 dB @ 9.1 Hz": 21.25, "62 dB @ 9.1 Hz": 21.25,
"86 dB @ 10 Hz": 20.0, "86 dB @ 10 Hz": 20.0,
@ -240,10 +252,11 @@
"step": 0.1, "step": 0.1,
"suffix": "", "suffix": "",
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "kp" "ch",
}, "kp"
],
"tip": "Proportional gain", "tip": "Proportional gain",
"lock": false "lock": false
}, },
@ -254,10 +267,11 @@
"step": 0.1, "step": 0.1,
"suffix": "Hz", "suffix": "Hz",
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "ki" "ch",
}, "ki"
],
"tip": "Integral gain", "tip": "Integral gain",
"lock": false "lock": false
}, },
@ -268,10 +282,11 @@
"step": 0.1, "step": 0.1,
"suffix": "s", "suffix": "s",
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "kd" "ch",
}, "kd"
],
"tip": "Differential gain", "tip": "Differential gain",
"lock": false "lock": false
}, },
@ -293,10 +308,11 @@
], ],
"decimals": 6, "decimals": 6,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "output_min" "ch",
}, "output_min"
],
"tip": "Minimum PID output", "tip": "Minimum PID output",
"lock": false "lock": false
}, },
@ -311,10 +327,11 @@
], ],
"decimals": 6, "decimals": 6,
"compactHeight": false, "compactHeight": false,
"thermostat:set_param": { "param": [
"topic": "pid", "pid",
"field": "output_max" "ch",
}, "output_max"
],
"tip": "Maximum PID output", "tip": "Maximum PID output",
"lock": false "lock": false
} }
@ -335,9 +352,10 @@
"step": 0.1, "step": 0.1,
"format": "{value:.4f}", "format": "{value:.4f}",
"compactHeight": false, "compactHeight": false,
"pid_autotune": { "pid_autotune": [
"params_name": "target_temp" "target_temp",
}, "ch"
],
"tip": "The target temperature to autotune for" "tip": "The target temperature to autotune for"
}, },
{ {
@ -349,12 +367,13 @@
"compactHeight": false, "compactHeight": false,
"step": 100, "step": 100,
"limits": [ "limits": [
0, -2000,
2000 2000
], ],
"pid_autotune": { "pid_autotune": [
"params_name": "test_current" "test_current",
}, "ch"
],
"tip": "The testing current when autotuning" "tip": "The testing current when autotuning"
}, },
{ {
@ -366,9 +385,10 @@
"prefix": "±", "prefix": "±",
"format": "{value:.4f}", "format": "{value:.4f}",
"compactHeight": false, "compactHeight": false,
"pid_autotune": { "pid_autotune": [
"params_name": "temp_swing" "temp_swing",
}, "ch"
],
"tip": "The temperature swing around the target" "tip": "The temperature swing around the target"
}, },
{ {
@ -379,9 +399,10 @@
"step": 0.1, "step": 0.1,
"format": "{value:.4f}", "format": "{value:.4f}",
"compactHeight": false, "compactHeight": false,
"pid_autotune": { "pid_autotune": [
"params_name": "lookback" "lookback",
}, "ch"
],
"tip": "Amount of time to lookback" "tip": "Amount of time to lookback"
}, },
{ {

View File

@ -266,33 +266,36 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes: for inner_param, change, data in changes:
if change == "value": if change == "value":
new_value = data if inner_param.opts.get("param", None) is not None:
if "thermostat:set_param" in inner_param.opts:
thermostat_param = inner_param.opts["thermostat:set_param"]
# Handle thermostat command irregularities
match inner_param.name(), new_value:
case "rate", "":
thermostat_param = thermostat_param.copy()
thermostat_param["field"] = "off"
case "control_method", "constant_current":
inner_param = inner_param.child("i_set")
thermostat_param = inner_param.opts["thermostat:set_param"]
new_value = inner_param.value()
case "control_method", "temperature_pid":
new_value = ""
if inner_param.opts.get("title", None).endswith(" (mA)"): if inner_param.opts.get("title", None).endswith(" (mA)"):
new_value /= 1000 # Given in mA data /= 1000 # Given in mA
inner_param.setOpts(lock=True)
await self.client.set_param(
channel=ch, value=new_value, **thermostat_param
)
inner_param.setOpts(lock=False)
if "pid_autotune" in inner_param.opts: thermostat_param = inner_param.opts["param"]
autotuner_param = inner_param.opts["pid_autotune"] if thermostat_param[1] == "ch":
self.autotuners.set_params(ch=ch, val=new_value, **autotuner_param) thermostat_param[1] = ch
if inner_param.name() == "rate" and data is None:
set_param_args = (*thermostat_param[:2], "off")
else:
set_param_args = (*thermostat_param, data)
param.child(*param.childPath(inner_param)).setOpts(lock=True)
await self.client.set_param(*set_param_args)
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]
if inner_param.opts["pid_autotune"][1] != "ch":
ch = inner_param.opts["pid_autotune"][1]
self.autotuners.set_params(autotuner_param, ch, data)
if inner_param.opts.get("activaters", None) is not None:
activater = inner_param.opts["activaters"][
inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values
]
if activater is not None:
if activater[1] == "ch":
activater[1] = ch
await self.client.set_param(*activater)
@asyncSlot() @asyncSlot()
async def pid_autotune_request(self, ch=0): async def pid_autotune_request(self, ch=0):