Compare commits

...

1 Commits

Author SHA1 Message Date
57d366e4d7 Control Panel: Use codenames for parameters
Without cosmetic changes, avoid embedding display text in the code.

For displayed string representations, use the `title` key, or for
`ListParameter`s, use the dictionary mapping method instead.
2025-03-28 11:20:32 +08:00
2 changed files with 101 additions and 75 deletions

View File

@ -84,15 +84,15 @@ class CtrlPanel(QObject):
self.params[i].setValue = self._setValue
self.params[i].sigTreeStateChanged.connect(self.send_command)
self.params[i].child("Save to flash").sigActivated.connect(
self.params[i].child("save").sigActivated.connect(
partial(self.save_settings, i)
)
self.params[i].child("Load from flash").sigActivated.connect(
self.params[i].child("load").sigActivated.connect(
partial(self.load_settings, i)
)
self.params[i].child(
"PID Config", "PID Auto Tune", "Run"
).sigActivated.connect(partial(self.pid_auto_tune_request, i))
self.params[i].child("pid", "pid_autotune", "run_pid").sigActivated.connect(
partial(self.pid_auto_tune_request, i)
)
self.thermostat.pid_update.connect(self.update_pid)
self.thermostat.report_update.connect(self.update_report)
@ -146,13 +146,13 @@ class CtrlPanel(QObject):
# 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)
@ -170,23 +170,23 @@ class CtrlPanel(QObject):
for settings in pid_settings:
channel = settings["channel"]
with QSignalBlocker(self.params[channel]):
self.params[channel].child("PID Config", "Kp").setValue(
self.params[channel].child("pid", "kp").setValue(
settings["parameters"]["kp"]
)
self.params[channel].child("PID Config", "Ki").setValue(
self.params[channel].child("pid", "ki").setValue(
settings["parameters"]["ki"]
)
self.params[channel].child("PID Config", "Kd").setValue(
self.params[channel].child("pid", "kd").setValue(
settings["parameters"]["kd"]
)
self.params[channel].child(
"PID Config", "PID Output Clamping", "Minimum"
"pid", "pid_output_clamping", "output_min"
).setValue(settings["parameters"]["output_min"] * 1000)
self.params[channel].child(
"PID Config", "PID Output Clamping", "Maximum"
"pid", "pid_output_clamping", "output_max"
).setValue(settings["parameters"]["output_max"] * 1000)
self.params[channel].child(
"Output Config", "Control Method", "Set Temperature"
"output", "control_method", "target"
).setValue(settings["target"])
@pyqtSlot(list)
@ -194,18 +194,18 @@ class CtrlPanel(QObject):
for settings in report_data:
channel = settings["channel"]
with QSignalBlocker(self.params[channel]):
self.params[channel].child("Output Config", "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 Config", "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
)
@ -214,13 +214,13 @@ class CtrlPanel(QObject):
for sh_param in sh_data:
channel = sh_param["channel"]
with QSignalBlocker(self.params[channel]):
self.params[channel].child("Thermistor Config", "T₀").setValue(
self.params[channel].child("thermistor", "t0").setValue(
sh_param["params"]["t0"] - 273.15
)
self.params[channel].child("Thermistor Config", "R₀").setValue(
self.params[channel].child("thermistor", "r0").setValue(
sh_param["params"]["r0"]
)
self.params[channel].child("Thermistor Config", "B").setValue(
self.params[channel].child("thermistor", "b").setValue(
sh_param["params"]["b"]
)
@ -229,39 +229,35 @@ class CtrlPanel(QObject):
for output_params in output_data:
channel = output_params["channel"]
with QSignalBlocker(self.params[channel]):
self.params[channel].child(
"Output Config", "Limits", "Max Voltage Difference"
).setValue(output_params["max_v"])
self.params[channel].child(
"Output Config", "Limits", "Max Cooling Current"
).setValue(output_params["max_i_pos"] * 1000)
self.params[channel].child(
"Output Config", "Limits", "Max Heating Current"
).setValue(output_params["max_i_neg"] * 1000)
self.params[channel].child("output", "limits", "max_v").setValue(
output_params["max_v"]
)
self.params[channel].child("output", "limits", "max_i_pos").setValue(
output_params["max_i_pos"] * 1000
)
self.params[channel].child("output", "limits", "max_i_neg").setValue(
output_params["max_i_neg"] * 1000
)
@pyqtSlot(list)
def update_postfilter(self, postfilter_data):
for postfilter_params in postfilter_data:
channel = postfilter_params["channel"]
with QSignalBlocker(self.params[channel]):
self.params[channel].child(
"Thermistor Config", "Postfilter Rate"
).setValue(postfilter_params["rate"])
self.params[channel].child("thermistor", "rate").setValue(
postfilter_params["rate"]
)
def update_pid_autotune(self, ch, state):
match state:
case PIDAutotuneState.OFF:
self.change_params_title(
ch, ("PID Config", "PID Auto Tune", "Run"), "Run"
)
self.change_params_title(ch, ("pid", "pid_autotune", "run_pid"), "Run")
case (
PIDAutotuneState.READY
| PIDAutotuneState.RELAY_STEP_UP
| PIDAutotuneState.RELAY_STEP_DOWN
):
self.change_params_title(
ch, ("PID Config", "PID Auto Tune", "Run"), "Stop"
)
self.change_params_title(ch, ("pid", "pid_autotune", "run_pid"), "Stop")
case PIDAutotuneState.SUCCEEDED:
self.info_box.display_info_box(
"PID Autotune Success",

View File

@ -1,38 +1,43 @@
{
"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 Config",
"name": "output",
"title": "Output Config",
"expanded": true,
"type": "group",
"children": [
{
"name": "Control Method",
"name": "control_method",
"title": "Control Method",
"type": "mutex",
"limits": [
"Constant Current",
"Temperature PID"
],
"value": "Constant Current",
"limits": {
"Constant Current": "constant_current",
"Temperature PID": "temperature_pid"
},
"value": "constant_current",
"thermostat:set_param": {
"topic": "output",
"field": "pid"
},
"children": [
{
"name": "Set Current",
"name": "i_set",
"title": "Set Current",
"type": "float",
"value": 0,
"step": 100,
@ -50,7 +55,8 @@
"lock": false
},
{
"name": "Set Temperature",
"name": "target",
"title": "Set Temperature",
"type": "float",
"value": 25,
"step": 0.1,
@ -68,12 +74,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,
@ -90,7 +98,8 @@
"lock": false
},
{
"name": "Max Heating Current",
"name": "max_i_neg",
"title": "Max Heating Current",
"type": "float",
"value": 0,
"step": 100,
@ -107,7 +116,8 @@
"lock": false
},
{
"name": "Max Voltage Difference",
"name": "max_v",
"title": "Max Voltage Difference",
"type": "float",
"value": 0,
"step": 0.1,
@ -128,12 +138,14 @@
]
},
{
"name": "Thermistor Config",
"name": "thermistor",
"title": "Thermistor Config",
"expanded": true,
"type": "group",
"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 Config",
"name": "pid",
"title": "PID Config",
"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 config to thermostat, applies on reset"
},
{
"name": "Load from flash",
"name": "load",
"title": "Load from flash",
"type": "action",
"tip": "Load config from flash"
}