Compare commits

...

10 Commits

Author SHA1 Message Date
6dcd1b6275 Keep i_set visible even when PID is engaged
Since i_set is also plotted, we would also want to see its precise value
too.
2024-07-18 18:08:39 +08:00
c75c8f2da0 Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes
elsewhere.
2024-07-18 18:08:39 +08:00
c754dcfb18 Remove "activater" option
Interpret commands directly in send_command
2024-07-18 18:08:38 +08:00
0b0bf26244 PID Autotune test current should only be positive 2024-07-18 18:08:38 +08:00
487bf24ffe More straightforward mapping to thermostat command
New tag "thermostat:set_param" used in JSON.
2024-07-18 18:08:36 +08:00
6372e03dff Separate tree and param changes 2024-07-18 18:08:10 +08:00
dbee457c09 i -> ch
and others
2024-07-18 18:08:10 +08:00
97c5f2a201 Remove unnessarily duplicated parameter tree
Huge source of confusion and easy bugs!
2024-07-18 18:08:10 +08:00
fad9008707 Remove unneccessary redirection
The child at inner_param's childpath to the root parameter... is just
inner_param.
2024-07-18 18:08:10 +08:00
bbd6774c75 Make send_command more readable 2024-07-18 18:08:10 +08:00
3 changed files with 122 additions and 170 deletions

View File

@ -6,42 +6,6 @@ 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
@ -65,28 +29,40 @@ 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=self.THERMOSTAT_PARAMETERS[ch], children=param_tree,
) )
for ch in range(self.NUM_CHANNELS) for ch in range(self.NUM_CHANNELS)
] ]
for i, tree in enumerate(self.trees_ui): for ch, tree in enumerate(self.trees_ui):
tree.setHeaderHidden(True) tree.setHeaderHidden(True)
tree.setParameters(self.params[i], showTop=False) tree.setParameters(self.params[ch], 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 handle in sigActivated_handles[i]: for ch, param in enumerate(self.params):
self.params[i].child(*handle[0]).sigActivated.connect(handle[1]) 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"
)
)
def _setValue(self, value, blockSignal=None): def _setValue(self, value, blockSignal=None):
""" """

View File

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

View File

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