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 9af4ffd125
commit 6a38f9b5a6
3 changed files with 98 additions and 70 deletions

View File

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

View File

@ -1,37 +1,42 @@
{
"ctrl_panel": [
{
"name": "Temperature",
"name": "temperature",
"title": "Temperature",
"type": "float",
"format": "{value:.4f} °C",
"readonly": true
},
{
"name": "Current through TEC",
"name": "tec_i",
"title": "Current through TEC",
"type": "float",
"suffix": "mA",
"decimals": 6,
"readonly": true
},
{
"name": "Output Settings",
"name": "output",
"title": "Output Settings",
"expanded": true,
"type": "group",
"children": [
{
"name": "Control Method",
"name": "control_method",
"title": "Control Method",
"type": "mutex",
"limits": [
"Constant Current",
"Temperature PID"
],
"limits": {
"Constant Current": "constant_current",
"Temperature PID": "temperature_pid"
},
"thermostat:set_param": {
"topic": "pwm",
"field": "pid"
},
"children": [
{
"name": "Set Current",
"name": "i_set",
"title": "Set Current",
"type": "float",
"value": 0,
"step": 100,
@ -49,7 +54,8 @@
"lock": false
},
{
"name": "Set Temperature",
"name": "target",
"title": "Set Temperature",
"type": "float",
"value": 25,
"step": 0.1,
@ -67,12 +73,14 @@
]
},
{
"name": "Limits",
"name": "limits",
"title": "Limits",
"expanded": true,
"type": "group",
"children": [
{
"name": "Max Cooling Current",
"name": "max_i_pos",
"title": "Max Cooling Current",
"type": "float",
"value": 0,
"step": 100,
@ -89,7 +97,8 @@
"lock": false
},
{
"name": "Max Heating Current",
"name": "max_i_neg",
"title": "Max Heating Current",
"type": "float",
"value": 0,
"step": 100,
@ -106,7 +115,8 @@
"lock": false
},
{
"name": "Max Voltage Difference",
"name": "max_v",
"title": "Max Voltage Difference",
"type": "float",
"value": 0,
"step": 0.1,
@ -127,13 +137,15 @@
]
},
{
"name": "Thermistor Settings",
"name": "thermistor",
"title": "Thermistor Settings",
"expanded": true,
"type": "group",
"tip": "Settings of the connected Thermistor",
"children": [
{
"name": "T₀",
"name": "t0",
"title": "T₀",
"type": "float",
"value": 25,
"step": 0.1,
@ -149,7 +161,8 @@
"lock": false
},
{
"name": "R₀",
"name": "r0",
"title": "R₀",
"type": "float",
"value": 10000,
"step": 1,
@ -162,7 +175,8 @@
"lock": false
},
{
"name": "B",
"name": "b",
"title": "B",
"type": "float",
"value": 3950,
"step": 1,
@ -175,7 +189,8 @@
"lock": false
},
{
"name": "Postfilter Rate",
"name": "rate",
"title": "Postfilter Rate",
"type": "list",
"value": 16.67,
"thermostat:set_param": {
@ -194,12 +209,14 @@
]
},
{
"name": "PID Settings",
"name": "pid",
"title": "PID Settings",
"expanded": true,
"type": "group",
"children": [
{
"name": "Kp",
"name": "kp",
"title": "Kp",
"type": "float",
"step": 0.1,
"suffix": "",
@ -210,7 +227,8 @@
"lock": false
},
{
"name": "Ki",
"name": "ki",
"title": "Ki",
"type": "float",
"step": 0.1,
"suffix": "Hz",
@ -221,7 +239,8 @@
"lock": false
},
{
"name": "Kd",
"name": "kd",
"title": "Kd",
"type": "float",
"step": 0.1,
"suffix": "s",
@ -232,12 +251,14 @@
"lock": false
},
{
"name": "PID Output Clamping",
"name": "pid_output_clamping",
"title": "PID Output Clamping",
"expanded": true,
"type": "group",
"children": [
{
"name": "Minimum",
"name": "output_min",
"title": "Minimum",
"type": "float",
"step": 100,
"limits": [
@ -253,7 +274,8 @@
"lock": false
},
{
"name": "Maximum",
"name": "output_max",
"title": "Maximum",
"type": "float",
"step": 100,
"limits": [
@ -271,12 +293,14 @@
]
},
{
"name": "PID Auto Tune",
"name": "pid_autotune",
"title": "PID Auto Tune",
"expanded": false,
"type": "group",
"children": [
{
"name": "Target Temperature",
"name": "target_temp",
"title": "Target Temperature",
"type": "float",
"value": 20,
"step": 0.1,
@ -284,7 +308,8 @@
"pid_autotune": "target_temp"
},
{
"name": "Test Current",
"name": "test_current",
"title": "Test Current",
"type": "float",
"value": 0,
"decimals": 6,
@ -297,7 +322,8 @@
"pid_autotune": "test_current"
},
{
"name": "Temperature Swing",
"name": "temp_swing",
"title": "Temperature Swing",
"type": "float",
"value": 1.5,
"step": 0.1,
@ -306,7 +332,8 @@
"pid_autotune": "temp_swing"
},
{
"name": "Lookback",
"name": "lookback",
"title": "Lookback",
"type": "float",
"value": 3.0,
"step": 0.1,
@ -314,7 +341,8 @@
"pid_autotune": "lookback"
},
{
"name": "Run",
"name": "run_pid",
"title": "Run",
"type": "action",
"tip": "Run"
}
@ -323,12 +351,14 @@
]
},
{
"name": "Save to flash",
"name": "save",
"title": "Save to flash",
"type": "action",
"tip": "Save settings to thermostat, applies on reset"
},
{
"name": "Load from flash",
"name": "load",
"title": "Load from flash",
"type": "action",
"tip": "Load settings from flash"
}

View File

@ -78,10 +78,10 @@ class MainWindow(QtWidgets.QMainWindow):
param_tree_sigActivated_handles = [
[
[["Save to flash"], partial(self.thermostat.save_cfg, ch)],
[["Load from flash"], partial(self.thermostat.load_cfg, ch)],
[["save"], partial(self.thermostat.save_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),
],
]
@ -275,13 +275,13 @@ class MainWindow(QtWidgets.QMainWindow):
# Handle thermostat command irregularities
match inner_param.name(), new_value:
case "Postfilter Rate", None:
case "rate", None:
thermostat_param = thermostat_param.copy()
thermostat_param["field"] = "off"
new_value = ""
case "Control Method", "Constant Current":
case "control_method", "constant_current":
return
case "Control Method", "Temperature PID":
case "control_method", "temperature_pid":
new_value = ""
inner_param.setOpts(lock=True)
@ -312,11 +312,11 @@ class MainWindow(QtWidgets.QMainWindow):
match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF:
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:
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)