Compare commits

...

9 Commits

Author SHA1 Message Date
3552a582f8 ctrl_panel: Keep i_set visible when PID engaged
Since i_set is also plotted, we would want to see its precise value too.
2024-07-19 15:55:43 +08:00
d7defecaaa ctrl_panel: Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes
elsewhere.
2024-07-19 15:49:19 +08:00
282f3d1e82 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:49:19 +08:00
d4171f002e 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:49:19 +08:00
1221ac4436 ctrl_panel: PID Auto Tune -> PID Autotune 2024-07-19 15:49:19 +08:00
abecac44d6 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:49:19 +08:00
8902052ee0 ctrl_panel: Appropriate 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:49:19 +08:00
fd7e22fd23 ctrl_panel: Pin down units for editable fields
Avoids awkward value editing
2024-07-19 15:49:19 +08:00
681a7539fe ctrl_panel: Improve postfilter description 2024-07-19 15:49:19 +08:00
3 changed files with 78 additions and 97 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):
for item in tree.listAllItems():
p = item.param
@ -65,31 +29,40 @@ class CtrlPanel(QObject):
self.trees_ui = trees_ui
self.NUM_CHANNELS = len(trees_ui)
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
self.params = [
Parameter.create(
name=f"Thermostat Channel {ch} Parameters",
type="group",
value=ch,
children=self.THERMOSTAT_PARAMETERS[ch],
children=param_tree,
)
for ch in range(self.NUM_CHANNELS)
]
for i, param in enumerate(self.params):
param.channel = i
for i, tree in enumerate(self.trees_ui):
for ch, tree in enumerate(self.trees_ui):
tree.setHeaderHidden(True)
tree.setParameters(self.params[i], showTop=False)
self.params[i].setValue = self._setValue
self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle)
tree.setParameters(self.params[ch], showTop=False)
set_tree_label_tips(tree)
for handle in sigActivated_handles[i]:
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):
"""
@ -161,7 +134,7 @@ class CtrlPanel(QObject):
)
if settings["tec_i"] is not None:
self.params[channel].child("tec_i").setValue(
settings["tec_i"] * 1000
settings["tec_i"]
)
@pyqtSlot("QVariantList")

View File

@ -12,7 +12,8 @@
"name": "tec_i",
"title": "Current through TEC",
"type": "float",
"suffix": "mA",
"siPrefix": true,
"suffix": "A",
"decimals": 6,
"readonly": true,
"tip": "The measured current through the TEC"
@ -27,7 +28,7 @@
{
"name": "control_method",
"title": "Control Method",
"type": "mutex",
"type": "list",
"limits": {
"Constant Current": "constant_current",
"Temperature PID": "temperature_pid"
@ -44,7 +45,7 @@
"children": [
{
"name": "i_set",
"title": "Set Current",
"title": "Set Current (mA)",
"type": "float",
"value": 0,
"step": 100,
@ -54,7 +55,7 @@
],
"triggerOnShow": true,
"decimals": 6,
"suffix": "mA",
"compactHeight": false,
"param": [
"pwm",
"ch",
@ -65,15 +66,17 @@
},
{
"name": "target",
"title": "Setpoint",
"title": "Setpoint (°C)",
"type": "float",
"visible": false,
"value": 25,
"step": 0.1,
"limits": [
-273,
300
],
"format": "{value:.4f} °C",
"format": "{value:.4f}",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -93,16 +96,16 @@
"children": [
{
"name": "max_i_pos",
"title": "Max Cooling Current",
"title": "Max Cooling Current (mA)",
"type": "float",
"value": 0,
"step": 100,
"decimals": 6,
"compactHeight": false,
"limits": [
0,
2000
],
"suffix": "mA",
"param": [
"pwm",
"ch",
@ -113,16 +116,16 @@
},
{
"name": "max_i_neg",
"title": "Max Heating Current",
"title": "Max Heating Current (mA)",
"type": "float",
"value": 0,
"step": 100,
"decimals": 6,
"compactHeight": false,
"limits": [
0,
2000
],
"suffix": "mA",
"param": [
"pwm",
"ch",
@ -133,16 +136,16 @@
},
{
"name": "max_v",
"title": "Max Absolute Voltage",
"title": "Max Absolute Voltage (V)",
"type": "float",
"value": 0,
"step": 0.1,
"limits": [
0,
5
4
],
"siPrefix": true,
"suffix": "V",
"compactHeight": false,
"param": [
"pwm",
"ch",
@ -164,7 +167,7 @@
"children": [
{
"name": "t0",
"title": "T₀",
"title": "T₀ (°C)",
"type": "float",
"value": 25,
"step": 0.1,
@ -172,7 +175,8 @@
-100,
100
],
"format": "{value:.4f} °C",
"format": "{value:.4f}",
"compactHeight": false,
"param": [
"s-h",
"ch",
@ -183,12 +187,12 @@
},
{
"name": "r0",
"title": "R₀",
"title": "R₀ (Ω)",
"type": "float",
"value": 10000,
"step": 1,
"siPrefix": true,
"suffix": "Ω",
"compactHeight": false,
"param": [
"s-h",
"ch",
@ -199,12 +203,12 @@
},
{
"name": "b",
"title": "B",
"title": "B (K)",
"type": "float",
"value": 3950,
"step": 1,
"suffix": "K",
"decimals": 4,
"compactHeight": false,
"param": [
"s-h",
"ch",
@ -215,7 +219,7 @@
},
{
"name": "rate",
"title": "Postfilter Rate",
"title": "50/60 Hz filter rejection",
"type": "list",
"value": 16.67,
"param": [
@ -225,10 +229,10 @@
],
"limits": {
"Off": null,
"16.67 Hz": 16.67,
"20 Hz": 20.0,
"21.25 Hz": 21.25,
"27 Hz": 27.0
"47 dB @ 10.41 Hz": 27.0,
"62 dB @ 9.1 Hz": 21.25,
"86 dB @ 10 Hz": 20.0,
"92 dB @ 8.4 Hz": 16.67
},
"tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz",
"lock": false
@ -248,6 +252,7 @@
"type": "float",
"step": 0.1,
"suffix": "",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -258,10 +263,10 @@
},
{
"name": "ki",
"title": "Ki",
"title": "Ki (Hz)",
"type": "float",
"step": 0.1,
"suffix": "Hz",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -272,10 +277,10 @@
},
{
"name": "kd",
"title": "Kd",
"title": "Kd (s)",
"type": "float",
"step": 0.1,
"suffix": "s",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -293,7 +298,7 @@
"children": [
{
"name": "output_min",
"title": "Minimum",
"title": "Minimum (mA)",
"type": "float",
"step": 100,
"limits": [
@ -301,7 +306,7 @@
2000
],
"decimals": 6,
"suffix": "mA",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -312,7 +317,7 @@
},
{
"name": "output_max",
"title": "Maximum",
"title": "Maximum (mA)",
"type": "float",
"step": 100,
"limits": [
@ -320,7 +325,7 @@
2000
],
"decimals": 6,
"suffix": "mA",
"compactHeight": false,
"param": [
"pid",
"ch",
@ -333,18 +338,19 @@
},
{
"name": "pid_autotune",
"title": "PID Auto Tune",
"title": "PID Autotune",
"expanded": false,
"type": "group",
"tip": "Automatically tune PID parameters",
"children": [
{
"name": "target_temp",
"title": "Target Temperature",
"title": "Target Temperature (°C)",
"type": "float",
"value": 20,
"step": 0.1,
"format": "{value:.4f} °C",
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"target_temp",
"ch"
@ -353,16 +359,16 @@
},
{
"name": "test_current",
"title": "Test Current",
"title": "Test Current (mA)",
"type": "float",
"value": 0,
"decimals": 6,
"compactHeight": false,
"step": 100,
"limits": [
-2000,
0,
2000
],
"suffix": "mA",
"pid_autotune": [
"test_current",
"ch"
@ -371,12 +377,13 @@
},
{
"name": "temp_swing",
"title": "Temperature Swing",
"title": "Temperature Swing (°C)",
"type": "float",
"value": 1.5,
"step": 0.1,
"prefix": "±",
"format": "{value:.4f} °C",
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"temp_swing",
"ch"
@ -385,11 +392,12 @@
},
{
"name": "lookback",
"title": "Lookback",
"title": "Lookback (s)",
"type": "float",
"value": 3.0,
"step": 0.1,
"format": "{value:.4f} s",
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"lookback",
"ch"

View File

@ -82,7 +82,7 @@ class MainWindow(QtWidgets.QMainWindow):
[["load"], partial(self.thermostat.load_cfg, ch)],
[
["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)
@ -262,12 +262,12 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(object, object)
async def send_command(self, param, changes):
"""Translates parameter tree changes into thermostat set_param calls"""
ch = param.channel
ch = param.value()
for inner_param, change, data in changes:
if change == "value":
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
thermostat_param = inner_param.opts["param"]
@ -283,10 +283,10 @@ class MainWindow(QtWidgets.QMainWindow):
param.child(*param.childPath(inner_param)).setOpts(lock=False)
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":
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:
activater = inner_param.opts["activaters"][
@ -298,7 +298,7 @@ class MainWindow(QtWidgets.QMainWindow):
await self.client.set_param(*activater)
@asyncSlot()
async def pid_auto_tune_request(self, ch=0):
async def pid_autotune_request(self, ch=0):
match self.autotuners.get_state(ch):
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
self.autotuners.load_params_and_set_ready(ch)