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):
for item in tree.listAllItems():
p = item.param
@ -29,40 +65,28 @@ 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, 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):
"""

View File

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

View File

@ -266,33 +266,36 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes:
if change == "value":
new_value = data
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("param", None) is not None:
if inner_param.opts.get("title", None).endswith(" (mA)"):
new_value /= 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)
data /= 1000 # Given in mA
if "pid_autotune" in inner_param.opts:
autotuner_param = inner_param.opts["pid_autotune"]
self.autotuners.set_params(ch=ch, val=new_value, **autotuner_param)
thermostat_param = inner_param.opts["param"]
if thermostat_param[1] == "ch":
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()
async def pid_autotune_request(self, ch=0):