ctrl_panel: Refer to Parameters by concise `name`s

For displayed string representations, use the `title` key, or for
`ListParameter`s, use the dictionary mapping method instead.
This commit is contained in:
atse 2024-07-11 10:25:52 +08:00
parent 7829ce6adf
commit 437c9cec34
3 changed files with 97 additions and 69 deletions

View File

@ -116,23 +116,23 @@ class CtrlPanel(QObject):
for settings in pid_settings: for settings in pid_settings:
channel = settings["channel"] channel = settings["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child("PID Settings", "Kp").setValue( self.params[channel].child("pid", "kp").setValue(
settings["parameters"]["kp"] settings["parameters"]["kp"]
) )
self.params[channel].child("PID Settings", "Ki").setValue( self.params[channel].child("pid", "ki").setValue(
settings["parameters"]["ki"] settings["parameters"]["ki"]
) )
self.params[channel].child("PID Settings", "Kd").setValue( self.params[channel].child("pid", "kd").setValue(
settings["parameters"]["kd"] settings["parameters"]["kd"]
) )
self.params[channel].child( self.params[channel].child(
"PID Settings", "PID Output Clamping", "Minimum" "pid", "pid_output_clamping", "output_min"
).setValue(settings["parameters"]["output_min"] * 1000) ).setValue(settings["parameters"]["output_min"] * 1000)
self.params[channel].child( self.params[channel].child(
"PID Settings", "PID Output Clamping", "Maximum" "pid", "pid_output_clamping", "output_max"
).setValue(settings["parameters"]["output_max"] * 1000) ).setValue(settings["parameters"]["output_max"] * 1000)
self.params[channel].child( self.params[channel].child(
"Output Settings", "Control Method", "Set Temperature" "output", "control_method", "target"
).setValue(settings["target"]) ).setValue(settings["target"])
@pyqtSlot("QVariantList") @pyqtSlot("QVariantList")
@ -140,20 +140,18 @@ class CtrlPanel(QObject):
for settings in report_data: for settings in report_data:
channel = settings["channel"] channel = settings["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child( self.params[channel].child("output", "control_method").setValue(
"Output Settings", "Control Method" "temperature_pid" if settings["pid_engaged"] else "constant_current"
).setValue(
"Temperature PID" if settings["pid_engaged"] else "Constant Current"
) )
self.params[channel].child( self.params[channel].child(
"Output Settings", "Control Method", "Set Current" "output", "control_method", "i_set"
).setValue(settings["i_set"] * 1000) ).setValue(settings["i_set"] * 1000)
if settings["temperature"] is not None: if settings["temperature"] is not None:
self.params[channel].child("Temperature").setValue( self.params[channel].child("temperature").setValue(
settings["temperature"] settings["temperature"]
) )
if settings["tec_i"] is not None: if settings["tec_i"] is not None:
self.params[channel].child("Current through TEC").setValue( self.params[channel].child("tec_i").setValue(
settings["tec_i"] * 1000 settings["tec_i"] * 1000
) )
@ -162,13 +160,13 @@ class CtrlPanel(QObject):
for sh_param in sh_data: for sh_param in sh_data:
channel = sh_param["channel"] channel = sh_param["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child("Thermistor Settings", "T₀").setValue( self.params[channel].child("thermistor", "t0").setValue(
sh_param["params"]["t0"] - 273.15 sh_param["params"]["t0"] - 273.15
) )
self.params[channel].child("Thermistor Settings", "R₀").setValue( self.params[channel].child("thermistor", "r0").setValue(
sh_param["params"]["r0"] sh_param["params"]["r0"]
) )
self.params[channel].child("Thermistor Settings", "B").setValue( self.params[channel].child("thermistor", "b").setValue(
sh_param["params"]["b"] sh_param["params"]["b"]
) )
@ -179,15 +177,15 @@ class CtrlPanel(QObject):
for pwm_params in pwm_data: for pwm_params in pwm_data:
channel = pwm_params["channel"] channel = pwm_params["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child( self.params[channel].child("output", "limits", "max_v").setValue(
"Output Settings", "Limits", "Max Voltage Difference" pwm_params["max_v"]["value"]
).setValue(pwm_params["max_v"]["value"]) )
self.params[channel].child( self.params[channel].child("output", "limits", "max_i_pos").setValue(
"Output Settings", "Limits", "Max Cooling Current" pwm_params["max_i_pos"]["value"] * 1000
).setValue(pwm_params["max_i_pos"]["value"] * 1000) )
self.params[channel].child( self.params[channel].child("output", "limits", "max_i_neg").setValue(
"Output Settings", "Limits", "Max Heating Current" pwm_params["max_i_neg"]["value"] * 1000
).setValue(pwm_params["max_i_neg"]["value"] * 1000) )
for limit in "max_i_pos", "max_i_neg", "max_v": for limit in "max_i_pos", "max_i_neg", "max_v":
if pwm_params[limit]["value"] == 0.0: if pwm_params[limit]["value"] == 0.0:
@ -199,6 +197,6 @@ class CtrlPanel(QObject):
for postfilter_params in postfilter_data: for postfilter_params in postfilter_data:
channel = postfilter_params["channel"] channel = postfilter_params["channel"]
with QSignalBlocker(self.params[channel]): with QSignalBlocker(self.params[channel]):
self.params[channel].child( self.params[channel].child("thermistor", "rate").setValue(
"Thermistor Settings", "Postfilter Rate" postfilter_params["rate"]
).setValue(postfilter_params["rate"]) )

View File

@ -1,30 +1,34 @@
{ {
"ctrl_panel": [ "ctrl_panel": [
{ {
"name": "Temperature", "name": "temperature",
"title": "Temperature",
"type": "float", "type": "float",
"format": "{value:.4f} °C", "format": "{value:.4f} °C",
"readonly": true "readonly": true
}, },
{ {
"name": "Current through TEC", "name": "tec_i",
"title": "Current through TEC",
"type": "float", "type": "float",
"suffix": "mA", "suffix": "mA",
"decimals": 6, "decimals": 6,
"readonly": true "readonly": true
}, },
{ {
"name": "Output Settings", "name": "output",
"title": "Output Settings",
"expanded": true, "expanded": true,
"type": "group", "type": "group",
"children": [ "children": [
{ {
"name": "Control Method", "name": "control_method",
"title": "Control Method",
"type": "mutex", "type": "mutex",
"limits": [ "limits": {
"Constant Current", "Constant Current": "constant_current",
"Temperature PID" "Temperature PID": "temperature_pid"
], },
"activaters": [ "activaters": [
null, null,
[ [
@ -35,7 +39,8 @@
], ],
"children": [ "children": [
{ {
"name": "Set Current", "name": "i_set",
"title": "Set Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -54,7 +59,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Set Temperature", "name": "target",
"title": "Set Temperature",
"type": "float", "type": "float",
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
@ -73,12 +79,14 @@
] ]
}, },
{ {
"name": "Limits", "name": "limits",
"title": "Limits",
"expanded": true, "expanded": true,
"type": "group", "type": "group",
"children": [ "children": [
{ {
"name": "Max Cooling Current", "name": "max_i_pos",
"title": "Max Cooling Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -96,7 +104,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Max Heating Current", "name": "max_i_neg",
"title": "Max Heating Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 100, "step": 100,
@ -114,7 +123,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Max Voltage Difference", "name": "max_v",
"title": "Max Voltage Difference",
"type": "float", "type": "float",
"value": 0, "value": 0,
"step": 0.1, "step": 0.1,
@ -136,13 +146,15 @@
] ]
}, },
{ {
"name": "Thermistor Settings", "name": "thermistor",
"title": "Thermistor Settings",
"expanded": true, "expanded": true,
"type": "group", "type": "group",
"tip": "Settings of the connected Thermistor", "tip": "Settings of the connected Thermistor",
"children": [ "children": [
{ {
"name": "T₀", "name": "t0",
"title": "T₀",
"type": "float", "type": "float",
"value": 25, "value": 25,
"step": 0.1, "step": 0.1,
@ -159,7 +171,8 @@
"lock": false "lock": false
}, },
{ {
"name": "R₀", "name": "r0",
"title": "R₀",
"type": "float", "type": "float",
"value": 10000, "value": 10000,
"step": 1, "step": 1,
@ -173,7 +186,8 @@
"lock": false "lock": false
}, },
{ {
"name": "B", "name": "b",
"title": "B",
"type": "float", "type": "float",
"value": 3950, "value": 3950,
"step": 1, "step": 1,
@ -187,7 +201,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Postfilter Rate", "name": "rate",
"title": "Postfilter Rate",
"type": "list", "type": "list",
"value": 16.67, "value": 16.67,
"param": [ "param": [
@ -207,12 +222,14 @@
] ]
}, },
{ {
"name": "PID Settings", "name": "pid",
"title": "PID Settings",
"expanded": true, "expanded": true,
"type": "group", "type": "group",
"children": [ "children": [
{ {
"name": "Kp", "name": "kp",
"title": "Kp",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "", "suffix": "",
@ -224,7 +241,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Ki", "name": "ki",
"title": "Ki",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "Hz", "suffix": "Hz",
@ -236,7 +254,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Kd", "name": "kd",
"title": "Kd",
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"suffix": "s", "suffix": "s",
@ -248,12 +267,14 @@
"lock": false "lock": false
}, },
{ {
"name": "PID Output Clamping", "name": "pid_output_clamping",
"title": "PID Output Clamping",
"expanded": true, "expanded": true,
"type": "group", "type": "group",
"children": [ "children": [
{ {
"name": "Minimum", "name": "output_min",
"title": "Minimum",
"type": "float", "type": "float",
"step": 100, "step": 100,
"limits": [ "limits": [
@ -270,7 +291,8 @@
"lock": false "lock": false
}, },
{ {
"name": "Maximum", "name": "output_max",
"title": "Maximum",
"type": "float", "type": "float",
"step": 100, "step": 100,
"limits": [ "limits": [
@ -289,12 +311,14 @@
] ]
}, },
{ {
"name": "PID Auto Tune", "name": "pid_autotune",
"title": "PID Auto Tune",
"expanded": false, "expanded": false,
"type": "group", "type": "group",
"children": [ "children": [
{ {
"name": "Target Temperature", "name": "target_temp",
"title": "Target Temperature",
"type": "float", "type": "float",
"value": 20, "value": 20,
"step": 0.1, "step": 0.1,
@ -305,7 +329,8 @@
] ]
}, },
{ {
"name": "Test Current", "name": "test_current",
"title": "Test Current",
"type": "float", "type": "float",
"value": 0, "value": 0,
"decimals": 6, "decimals": 6,
@ -321,7 +346,8 @@
] ]
}, },
{ {
"name": "Temperature Swing", "name": "temp_swing",
"title": "Temperature Swing",
"type": "float", "type": "float",
"value": 1.5, "value": 1.5,
"step": 0.1, "step": 0.1,
@ -333,7 +359,8 @@
] ]
}, },
{ {
"name": "Lookback", "name": "lookback",
"title": "Lookback",
"type": "float", "type": "float",
"value": 3.0, "value": 3.0,
"step": 0.1, "step": 0.1,
@ -344,7 +371,8 @@
] ]
}, },
{ {
"name": "Run", "name": "run_pid",
"title": "Run",
"type": "action", "type": "action",
"tip": "Run" "tip": "Run"
} }
@ -353,12 +381,14 @@
] ]
}, },
{ {
"name": "Save to flash", "name": "save",
"title": "Save to flash",
"type": "action", "type": "action",
"tip": "Save settings to thermostat, applies on reset" "tip": "Save settings to thermostat, applies on reset"
}, },
{ {
"name": "Load from flash", "name": "load",
"title": "Load from flash",
"type": "action", "type": "action",
"tip": "Load settings from flash" "tip": "Load settings from flash"
} }

View File

@ -78,10 +78,10 @@ class MainWindow(QtWidgets.QMainWindow):
param_tree_sigActivated_handles = [ param_tree_sigActivated_handles = [
[ [
[["Save to flash"], partial(self.thermostat.save_cfg, ch)], [["save"], partial(self.thermostat.save_cfg, ch)],
[["Load from flash"], partial(self.thermostat.load_cfg, ch)], [["load"], partial(self.thermostat.load_cfg, ch)],
[ [
["PID Settings", "PID Auto Tune", "Run"], ["pid", "pid_autotune", "run_pid"],
partial(self.pid_auto_tune_request, ch), partial(self.pid_auto_tune_request, ch),
], ],
] ]
@ -274,7 +274,7 @@ class MainWindow(QtWidgets.QMainWindow):
if thermostat_param[1] == "ch": if thermostat_param[1] == "ch":
thermostat_param[1] = ch thermostat_param[1] = ch
if inner_param.name() == "Postfilter Rate" and data is None: if inner_param.name() == "rate" and data is None:
set_param_args = (*thermostat_param[:2], "off") set_param_args = (*thermostat_param[:2], "off")
else: else:
set_param_args = (*thermostat_param, data) set_param_args = (*thermostat_param, data)
@ -290,7 +290,7 @@ class MainWindow(QtWidgets.QMainWindow):
if inner_param.opts.get("activaters", None) is not None: if inner_param.opts.get("activaters", None) is not None:
activater = inner_param.opts["activaters"][ activater = inner_param.opts["activaters"][
inner_param.opts["limits"].index(data) inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values
] ]
if activater is not None: if activater is not None:
if activater[1] == "ch": if activater[1] == "ch":
@ -315,11 +315,11 @@ class MainWindow(QtWidgets.QMainWindow):
match self.autotuners.get_state(ch): match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF: case PIDAutotuneState.STATE_OFF:
self.ctrl_panel_view.change_params_title( self.ctrl_panel_view.change_params_title(
ch, ("PID Settings", "PID Auto Tune", "Run"), "Run" ch, ("pid", "pid_autotune", "run_pid"), "Run"
) )
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN: case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
self.ctrl_panel_view.change_params_title( self.ctrl_panel_view.change_params_title(
ch, ("PID Settings", "PID Auto Tune", "Run"), "Stop" ch, ("pid", "pid_autotune", "run_pid"), "Stop"
) )
ch_tuning.append(ch) ch_tuning.append(ch)