Compare commits

...

13 Commits

Author SHA1 Message Date
21eb13ed6f ctrl_panel: Keep i_set visible when PID engaged
Since i_set is also plotted, we would also want to see its precise value
too.
2024-07-19 15:14:19 +08:00
646452f559 ctrl_panel: Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes
elsewhere.
2024-07-19 15:14:19 +08:00
46a22a9c32 ctrl_panel: Limits fixes
* PID Autotune test current should be positive

* Maximum absolute voltage should be 4 V not 5 V
2024-07-19 15:14:19 +08:00
8ec7bb833a ctrl_panel: Code cleanup
* Remove unnecessary duplication of `THERMOSTAT_PARAMETERS`

* i -> ch

* Separate ParameterTree and Parameter initiation

* Remove extra "channel" option to root parameters, as the "value"
option is already the channel number
2024-07-19 15:14:19 +08:00
02d04dbae5 ctrl_panel: PID Auto Tune -> PID Autotune 2024-07-19 15:14:19 +08:00
85ff340b6f ctrl_panel: Stop crushing spinboxes
It might not be the case on some themes, but on the default Qt theme the
spinbox are a bit too short for the containing numbers. See
https://github.com/pyqtgraph/pyqtgraph/issues/701.
2024-07-19 15:14:19 +08:00
d844c02a3a ctrl_panel: Approriate units for measured current
Allow the readonly display of current to vary its SI prefix in the unit,
since as a display entry it won't have the unit adjustment problem.
2024-07-19 15:13:49 +08:00
8a4d861672 ctrl_panel: Pin down units for editable fields
Avoids awkward value editing
2024-07-19 11:12:38 +08:00
b668c699fb ctrl_panel: Improve postfilter description 2024-07-19 11:11:59 +08:00
eb3719044f ctrl_panel: Add tooltips
For users' better understanding of what the parameters do
2024-07-19 11:11:55 +08:00
8ac4a32106 ctrl_panel: Refer to Parameters by concise names
For displayed string representations, use the `title` key, or for
`ListParameter`s, use the dictionary mapping method instead.
2024-07-16 15:08:42 +08:00
493088f4a5 ctrl_panel: Config -> Settings 2024-07-16 15:08:05 +08:00
2ae58b9abb Format JSON 2024-07-16 15:00:10 +08:00
4 changed files with 497 additions and 450 deletions

View File

@ -117,14 +117,14 @@ class Thermostat(QObject, metaclass=PropertyMeta):
async def save_cfg(self, ch): async def save_cfg(self, ch):
await self._client.save_config(ch) await self._client.save_config(ch)
self.info_box_trigger.emit( self.info_box_trigger.emit(
"Config loaded", f"Channel {ch} Config has been loaded from flash." "Settings loaded", f"Channel {ch} Settings has been loaded to flash."
) )
@asyncSlot() @asyncSlot()
async def load_cfg(self, ch): async def load_cfg(self, ch):
await self._client.load_config(ch) await self._client.load_config(ch)
self.info_box_trigger.emit( self.info_box_trigger.emit(
"Config loaded", f"Channel {ch} Config has been loaded from flash." "Settings loaded", f"Channel {ch} Settings has been loaded from flash."
) )
async def dfu(self): async def dfu(self):

View File

@ -6,40 +6,11 @@ from pyqtgraph.parametertree import (
) )
class MutexParameter(pTypes.ListParameter): def set_tree_label_tips(tree):
""" for item in tree.listAllItems():
Mutually exclusive parameter where only one of its children is visible at a time, list selectable. p = item.param
if "tip" in p.opts:
The ordering of the list items determines which children will be visible. item.setToolTip(0, p.opts["tip"])
"""
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)
class CtrlPanel(QObject): class CtrlPanel(QObject):
@ -58,29 +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, param in enumerate(self.params): for ch, tree in enumerate(self.trees_ui):
param.channel = i
for i, 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)
for handle in sigActivated_handles[i]: set_tree_label_tips(tree)
self.params[i].child(*handle[0]).sigActivated.connect(handle[1])
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"
)
)
def _setValue(self, value, blockSignal=None): def _setValue(self, value, blockSignal=None):
""" """
@ -116,23 +98,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 Config", "Kp").setValue( self.params[channel].child("pid", "kp").setValue(
settings["parameters"]["kp"] settings["parameters"]["kp"]
) )
self.params[channel].child("PID Config", "Ki").setValue( self.params[channel].child("pid", "ki").setValue(
settings["parameters"]["ki"] settings["parameters"]["ki"]
) )
self.params[channel].child("PID Config", "Kd").setValue( self.params[channel].child("pid", "kd").setValue(
settings["parameters"]["kd"] settings["parameters"]["kd"]
) )
self.params[channel].child( self.params[channel].child(
"PID Config", "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 Config", "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 Config", "Control Method", "Set Temperature" "output", "control_method", "target"
).setValue(settings["target"]) ).setValue(settings["target"])
@pyqtSlot("QVariantList") @pyqtSlot("QVariantList")
@ -140,19 +122,19 @@ 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("Output Config", "Control Method").setValue( self.params[channel].child("output", "control_method").setValue(
"Temperature PID" if settings["pid_engaged"] else "Constant Current" "temperature_pid" if settings["pid_engaged"] else "constant_current"
) )
self.params[channel].child( self.params[channel].child(
"Output Config", "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"]
) )
@pyqtSlot("QVariantList") @pyqtSlot("QVariantList")
@ -160,13 +142,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 Config", "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 Config", "R₀").setValue( self.params[channel].child("thermistor", "r0").setValue(
sh_param["params"]["r0"] sh_param["params"]["r0"]
) )
self.params[channel].child("Thermistor Config", "B").setValue( self.params[channel].child("thermistor", "b").setValue(
sh_param["params"]["b"] sh_param["params"]["b"]
) )
@ -177,15 +159,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 Config", "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 Config", "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 Config", "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:
@ -197,6 +179,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 Config", "Postfilter Rate" postfilter_params["rate"]
).setValue(postfilter_params["rate"]) )

View File

@ -1,365 +1,430 @@
{ {
"ctrl_panel":[ "ctrl_panel": [
{ {
"name":"Temperature", "name": "temperature",
"type":"float", "title": "Temperature",
"format":"{value:.4f} °C", "type": "float",
"readonly":true "format": "{value:.4f} °C",
}, "readonly": true,
{ "tip": "The measured temperature at the thermistor"
"name":"Current through TEC", },
"type":"float", {
"suffix":"mA", "name": "tec_i",
"decimals":6, "title": "Current through TEC",
"readonly":true "type": "float",
}, "siPrefix": true,
{ "suffix": "A",
"name":"Output Config", "decimals": 6,
"expanded":true, "readonly": true,
"type":"group", "tip": "The measured current through the TEC"
"children":[ },
{ {
"name":"Control Method", "name": "output",
"type":"mutex", "title": "Output Settings",
"limits":[ "expanded": true,
"Constant Current", "type": "group",
"Temperature PID" "tip": "Settings of the output to the TEC",
], "children": [
"activaters":[ {
null, "name": "control_method",
[ "title": "Control Method",
"pwm", "type": "list",
"ch", "limits": {
"pid" "Constant Current": "constant_current",
] "Temperature PID": "temperature_pid"
], },
"children":[ "activaters": [
{ null,
"name":"Set Current", [
"type":"float", "pwm",
"value":0, "ch",
"step":100, "pid"
"limits":[ ]
-2000, ],
2000 "tip": "Select control method of output",
], "children": [
"triggerOnShow":true, {
"decimals":6, "name": "i_set",
"suffix":"mA", "title": "Set Current (mA)",
"param":[ "type": "float",
"pwm", "value": 0,
"ch", "step": 100,
"i_set" "limits": [
], -2000,
"lock":false 2000
}, ],
{ "triggerOnShow": true,
"name":"Set Temperature", "decimals": 6,
"type":"float", "compactHeight": false,
"value":25, "param": [
"step":0.1, "pwm",
"limits":[ "ch",
-273, "i_set"
300 ],
], "tip": "The set current through TEC",
"format":"{value:.4f} °C", "lock": false
"param":[ },
"pid", {
"ch", "name": "target",
"target" "title": "Setpoint (°C)",
], "type": "float",
"lock":false "visible": false,
} "value": 25,
] "step": 0.1,
}, "limits": [
{ -273,
"name":"Limits", 300
"expanded":true, ],
"type":"group", "format": "{value:.4f}",
"children":[ "compactHeight": false,
{ "param": [
"name":"Max Cooling Current", "pid",
"type":"float", "ch",
"value":0, "target"
"step":100, ],
"decimals":6, "tip": "The temperature setpoint of the TEC",
"limits":[ "lock": false
0, }
2000 ]
], },
"suffix":"mA", {
"param":[ "name": "limits",
"pwm", "title": "Limits",
"ch", "expanded": true,
"max_i_pos" "type": "group",
], "tip": "The limits of output, with the polarity at the front panel as reference",
"lock":false "children": [
}, {
{ "name": "max_i_pos",
"name":"Max Heating Current", "title": "Max Cooling Current (mA)",
"type":"float", "type": "float",
"value":0, "value": 0,
"step":100, "step": 100,
"decimals":6, "decimals": 6,
"limits":[ "compactHeight": false,
0, "limits": [
2000 0,
], 2000
"suffix":"mA", ],
"param":[ "param": [
"pwm", "pwm",
"ch", "ch",
"max_i_neg" "max_i_pos"
], ],
"lock":false "tip": "The maximum cooling (+ve) current through the output pins",
}, "lock": false
{ },
"name":"Max Voltage Difference", {
"type":"float", "name": "max_i_neg",
"value":0, "title": "Max Heating Current (mA)",
"step":0.1, "type": "float",
"limits":[ "value": 0,
0, "step": 100,
5 "decimals": 6,
], "compactHeight": false,
"siPrefix":true, "limits": [
"suffix":"V", 0,
"param":[ 2000
"pwm", ],
"ch", "param": [
"max_v" "pwm",
], "ch",
"lock":false "max_i_neg"
} ],
] "tip": "The maximum heating (-ve) current through the output pins",
} "lock": false
] },
}, {
{ "name": "max_v",
"name":"Thermistor Config", "title": "Max Absolute Voltage (V)",
"expanded":true, "type": "float",
"type":"group", "value": 0,
"children":[ "step": 0.1,
{ "limits": [
"name":"T₀", 0,
"type":"float", 4
"value":25, ],
"step":0.1, "siPrefix": true,
"limits":[ "compactHeight": false,
-100, "param": [
100 "pwm",
], "ch",
"format":"{value:.4f} °C", "max_v"
"param":[ ],
"s-h", "tip": "The maximum voltage (in both directions) across the output pins",
"ch", "lock": false
"t0" }
], ]
"lock":false }
}, ]
{ },
"name":"R₀", {
"type":"float", "name": "thermistor",
"value":10000, "title": "Thermistor Settings",
"step":1, "expanded": true,
"siPrefix":true, "type": "group",
"suffix":"Ω", "tip": "Settings of the connected thermistor\n- Parameters for the resistance to temperature conversion (with the B-Parameter equation)\n- Settings for the 50/60 Hz filter with the thermistor",
"param":[ "children": [
"s-h", {
"ch", "name": "t0",
"r0" "title": "T₀ (°C)",
], "type": "float",
"lock":false "value": 25,
}, "step": 0.1,
{ "limits": [
"name":"B", -100,
"type":"float", 100
"value":3950, ],
"step":1, "format": "{value:.4f}",
"suffix":"K", "compactHeight": false,
"decimals":4, "param": [
"param":[ "s-h",
"s-h", "ch",
"ch", "t0"
"b" ],
], "tip": "The base temperature",
"lock":false "lock": false
}, },
{ {
"name":"Postfilter Rate", "name": "r0",
"type":"list", "title": "R₀ (Ω)",
"value":16.67, "type": "float",
"param":[ "value": 10000,
"postfilter", "step": 1,
"ch", "siPrefix": true,
"rate" "compactHeight": false,
], "param": [
"limits":{ "s-h",
"Off":null, "ch",
"16.67 Hz":16.67, "r0"
"20 Hz":20.0, ],
"21.25 Hz":21.25, "tip": "The resistance of the thermistor at base temperature T₀",
"27 Hz":27.0 "lock": false
}, },
"lock":false {
} "name": "b",
] "title": "B (K)",
}, "type": "float",
{ "value": 3950,
"name":"PID Config", "step": 1,
"expanded":true, "decimals": 4,
"type":"group", "compactHeight": false,
"children":[ "param": [
{ "s-h",
"name":"Kp", "ch",
"type":"float", "b"
"step":0.1, ],
"suffix":"", "tip": "The Beta Parameter",
"param":[ "lock": false
"pid", },
"ch", {
"kp" "name": "rate",
], "title": "50/60 Hz filter rejection",
"lock":false "type": "list",
}, "value": 16.67,
{ "param": [
"name":"Ki", "postfilter",
"type":"float", "ch",
"step":0.1, "rate"
"suffix":"Hz", ],
"param":[ "limits": {
"pid", "Off": null,
"ch", "47 dB @ 10.41 Hz": 27.0,
"ki" "62 dB @ 9.1 Hz": 21.25,
], "86 dB @ 10 Hz": 20.0,
"lock":false "92 dB @ 8.4 Hz": 16.67
}, },
{ "tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz",
"name":"Kd", "lock": false
"type":"float", }
"step":0.1, ]
"suffix":"s", },
"param":[ {
"pid", "name": "pid",
"ch", "title": "PID Settings",
"kd" "expanded": true,
], "type": "group",
"lock":false "tip": "Settings of PID parameters and clamping",
}, "children": [
{ {
"name":"PID Output Clamping", "name": "kp",
"expanded":true, "title": "Kp",
"type":"group", "type": "float",
"children":[ "step": 0.1,
{ "suffix": "",
"name":"Minimum", "compactHeight": false,
"type":"float", "param": [
"step":100, "pid",
"limits":[ "ch",
-2000, "kp"
2000 ],
], "tip": "Proportional gain",
"decimals":6, "lock": false
"suffix":"mA", },
"param":[ {
"pid", "name": "ki",
"ch", "title": "Ki (Hz)",
"output_min" "type": "float",
], "step": 0.1,
"lock":false "compactHeight": false,
}, "param": [
{ "pid",
"name":"Maximum", "ch",
"type":"float", "ki"
"step":100, ],
"limits":[ "tip": "Integral gain",
-2000, "lock": false
2000 },
], {
"decimals":6, "name": "kd",
"suffix":"mA", "title": "Kd (s)",
"param":[ "type": "float",
"pid", "step": 0.1,
"ch", "compactHeight": false,
"output_max" "param": [
], "pid",
"lock":false "ch",
} "kd"
] ],
}, "tip": "Differential gain",
{ "lock": false
"name":"PID Auto Tune", },
"expanded":false, {
"type":"group", "name": "pid_output_clamping",
"children":[ "title": "PID Output Clamping",
{ "expanded": true,
"name":"Target Temperature", "type": "group",
"type":"float", "tip": "Clamps PID outputs to specified range\nCould be different than output limits",
"value":20, "children": [
"step":0.1, {
"format":"{value:.4f} °C", "name": "output_min",
"pid_autotune":[ "title": "Minimum (mA)",
"target_temp", "type": "float",
"ch" "step": 100,
] "limits": [
}, -2000,
{ 2000
"name":"Test Current", ],
"type":"float", "decimals": 6,
"value":0, "compactHeight": false,
"decimals":6, "param": [
"step":100, "pid",
"limits":[ "ch",
-2000, "output_min"
2000 ],
], "tip": "Minimum PID output",
"suffix":"mA", "lock": false
"pid_autotune":[ },
"test_current", {
"ch" "name": "output_max",
] "title": "Maximum (mA)",
}, "type": "float",
{ "step": 100,
"name":"Temperature Swing", "limits": [
"type":"float", -2000,
"value":1.5, 2000
"step":0.1, ],
"prefix":"±", "decimals": 6,
"format":"{value:.4f} °C", "compactHeight": false,
"pid_autotune":[ "param": [
"temp_swing", "pid",
"ch" "ch",
] "output_max"
}, ],
{ "tip": "Maximum PID output",
"name":"Lookback", "lock": false
"type":"float", }
"value":3.0, ]
"step":0.1, },
"format":"{value:.4f} s", {
"pid_autotune":[ "name": "pid_autotune",
"title": "PID Autotune",
"expanded": false,
"type": "group",
"tip": "Automatically tune PID parameters",
"children": [
{
"name": "target_temp",
"title": "Target Temperature (°C)",
"type": "float",
"value": 20,
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"target_temp",
"ch"
],
"tip": "The target temperature to autotune for"
},
{
"name": "test_current",
"title": "Test Current (mA)",
"type": "float",
"value": 0,
"decimals": 6,
"compactHeight": false,
"step": 100,
"limits": [
0,
2000
],
"pid_autotune": [
"test_current",
"ch"
],
"tip": "The testing current when autotuning"
},
{
"name": "temp_swing",
"title": "Temperature Swing (°C)",
"type": "float",
"value": 1.5,
"step": 0.1,
"prefix": "±",
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"temp_swing",
"ch"
],
"tip": "The temperature swing around the target"
},
{
"name": "lookback",
"title": "Lookback (s)",
"type": "float",
"value": 3.0,
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"lookback", "lookback",
"ch" "ch"
] ],
"tip": "Amount of time referenced for tuning"
}, },
{ {
"name":"Run", "name": "run_pid",
"type":"action", "title": "Run",
"tip":"Run" "type": "action",
} "tip": "Run PID Autotune with above settings"
] }
} ]
] }
}, ]
{ },
"name":"Save to flash", {
"type":"action", "name": "save",
"tip":"Save config to thermostat, applies on reset" "title": "Save to flash",
}, "type": "action",
{ "tip": "Save settings to thermostat, applies on reset"
"name":"Load from flash", },
"type":"action", {
"tip":"Load config from flash" "name": "load",
} "title": "Load from flash",
] "type": "action",
} "tip": "Load settings from thermostat"
}
]
}

View File

@ -78,11 +78,11 @@ 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 Config", "PID Auto Tune", "Run"], ["pid", "pid_autotune", "run_pid"],
partial(self.pid_auto_tune_request, ch), partial(self.pid_autotune_request, ch),
], ],
] ]
for ch in range(self.NUM_CHANNELS) for ch in range(self.NUM_CHANNELS)
@ -262,19 +262,19 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(object, object) @asyncSlot(object, object)
async def send_command(self, param, changes): async def send_command(self, param, changes):
"""Translates parameter tree changes into thermostat set_param calls""" """Translates parameter tree changes into thermostat set_param calls"""
ch = param.channel ch = param.value()
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: if inner_param.opts.get("param", None) is not None:
if inner_param.opts.get("suffix", None) == "mA": if inner_param.opts.get("title", None).endswith(" (mA)"):
data /= 1000 # Given in mA data /= 1000 # Given in mA
thermostat_param = inner_param.opts["param"] thermostat_param = inner_param.opts["param"]
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)
@ -283,14 +283,14 @@ class MainWindow(QtWidgets.QMainWindow):
param.child(*param.childPath(inner_param)).setOpts(lock=False) param.child(*param.childPath(inner_param)).setOpts(lock=False)
if inner_param.opts.get("pid_autotune", None) is not None: if inner_param.opts.get("pid_autotune", None) is not None:
auto_tuner_param = inner_param.opts["pid_autotune"][0] autotuner_param = inner_param.opts["pid_autotune"][0]
if inner_param.opts["pid_autotune"][1] != "ch": if inner_param.opts["pid_autotune"][1] != "ch":
ch = inner_param.opts["pid_autotune"][1] ch = inner_param.opts["pid_autotune"][1]
self.autotuners.set_params(auto_tuner_param, ch, data) self.autotuners.set_params(autotuner_param, ch, data)
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":
@ -298,7 +298,7 @@ class MainWindow(QtWidgets.QMainWindow):
await self.client.set_param(*activater) await self.client.set_param(*activater)
@asyncSlot() @asyncSlot()
async def pid_auto_tune_request(self, ch=0): async def pid_autotune_request(self, ch=0):
match self.autotuners.get_state(ch): match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED: case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
self.autotuners.load_params_and_set_ready(ch) self.autotuners.load_params_and_set_ready(ch)
@ -315,18 +315,18 @@ 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 Config", "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 Config", "PID Auto Tune", "Run"), "Stop" ch, ("pid", "pid_autotune", "run_pid"), "Stop"
) )
ch_tuning.append(ch) ch_tuning.append(ch)
case PIDAutotuneState.STATE_SUCCEEDED: case PIDAutotuneState.STATE_SUCCEEDED:
self.info_box.display_info_box( self.info_box.display_info_box(
"PID Autotune Success", "PID Autotune Success",
f"Channel {ch} PID Config has been loaded to Thermostat. Regulating temperature.", f"Channel {ch} PID Settings has been loaded to Thermostat. Regulating temperature.",
) )
self.info_box.show() self.info_box.show()