Compare commits

...

10 Commits

Author SHA1 Message Date
6dcd1b6275 Keep i_set visible even when PID is engaged
Since i_set is also plotted, we would also want to see its precise value
too.
2024-07-18 18:08:39 +08:00
c75c8f2da0 Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes
elsewhere.
2024-07-18 18:08:39 +08:00
c754dcfb18 Remove "activater" option
Interpret commands directly in send_command
2024-07-18 18:08:38 +08:00
0b0bf26244 PID Autotune test current should only be positive 2024-07-18 18:08:38 +08:00
487bf24ffe More straightforward mapping to thermostat command
New tag "thermostat:set_param" used in JSON.
2024-07-18 18:08:36 +08:00
6372e03dff Separate tree and param changes 2024-07-18 18:08:10 +08:00
dbee457c09 i -> ch
and others
2024-07-18 18:08:10 +08:00
97c5f2a201 Remove unnessarily duplicated parameter tree
Huge source of confusion and easy bugs!
2024-07-18 18:08:10 +08:00
fad9008707 Remove unneccessary redirection
The child at inner_param's childpath to the root parameter... is just
inner_param.
2024-07-18 18:08:10 +08:00
bbd6774c75 Make send_command more readable 2024-07-18 18:08:10 +08:00
3 changed files with 122 additions and 170 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,28 +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, 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):
"""

View File

@ -28,19 +28,15 @@
{
"name": "control_method",
"title": "Control Method",
"type": "mutex",
"type": "list",
"limits": {
"Constant Current": "constant_current",
"Temperature PID": "temperature_pid"
},
"activaters": [
null,
[
"pwm",
"ch",
"pid"
]
],
"thermostat:set_param": {
"topic": "pwm",
"field": "pid"
},
"tip": "Select control method of output",
"children": [
{
@ -56,11 +52,10 @@
"triggerOnShow": true,
"decimals": 6,
"compactHeight": false,
"param": [
"pwm",
"ch",
"i_set"
],
"thermostat:set_param": {
"topic": "pwm",
"field": "i_set"
},
"tip": "The set current through TEC",
"lock": false
},
@ -68,6 +63,7 @@
"name": "target",
"title": "Set Temperature (°C)",
"type": "float",
"visible": false,
"value": 25,
"step": 0.1,
"limits": [
@ -76,11 +72,10 @@
],
"format": "{value:.4f}",
"compactHeight": false,
"param": [
"pid",
"ch",
"target"
],
"thermostat:set_param": {
"topic": "pid",
"field": "target"
},
"tip": "The target temperature of the TEC",
"lock": false
}
@ -105,11 +100,10 @@
0,
2000
],
"param": [
"pwm",
"ch",
"max_i_pos"
],
"thermostat:set_param": {
"topic": "pwm",
"field": "max_i_pos"
},
"tip": "The maximum cooling (+ve) current through the output pins",
"lock": false
},
@ -125,11 +119,10 @@
0,
2000
],
"param": [
"pwm",
"ch",
"max_i_neg"
],
"thermostat:set_param": {
"topic": "pwm",
"field": "max_i_neg"
},
"tip": "The maximum heating (-ve) current through the output pins",
"lock": false
},
@ -145,11 +138,10 @@
],
"siPrefix": true,
"compactHeight": false,
"param": [
"pwm",
"ch",
"max_v"
],
"thermostat:set_param": {
"topic": "pwm",
"field": "max_v"
},
"tip": "The maximum voltage across the output pins",
"lock": false
}
@ -176,11 +168,10 @@
],
"format": "{value:.4f}",
"compactHeight": false,
"param": [
"s-h",
"ch",
"t0"
],
"thermostat:set_param": {
"topic": "s-h",
"field": "t0"
},
"tip": "The origin temperature",
"lock": false
},
@ -192,11 +183,10 @@
"step": 1,
"siPrefix": true,
"compactHeight": false,
"param": [
"s-h",
"ch",
"r0"
],
"thermostat:set_param": {
"topic": "s-h",
"field": "r0"
},
"tip": "The resistance of the thermistor at origin temperature T₀",
"lock": false
},
@ -208,11 +198,10 @@
"step": 1,
"decimals": 4,
"compactHeight": false,
"param": [
"s-h",
"ch",
"b"
],
"thermostat:set_param": {
"topic": "s-h",
"field": "b"
},
"tip": "The B (or Beta) Parameter",
"lock": false
},
@ -221,13 +210,12 @@
"title": "Postfilter Rejection",
"type": "list",
"value": 16.67,
"param": [
"postfilter",
"ch",
"rate"
],
"thermostat:set_param": {
"topic": "postfilter",
"field": "rate"
},
"limits": {
"Off": null,
"Off": "",
"47 dB @ 10.41 Hz": 27.0,
"62 dB @ 9.1 Hz": 21.25,
"86 dB @ 10 Hz": 20.0,
@ -252,11 +240,10 @@
"step": 0.1,
"suffix": "",
"compactHeight": false,
"param": [
"pid",
"ch",
"kp"
],
"thermostat:set_param": {
"topic": "pid",
"field": "kp"
},
"tip": "Proportional gain",
"lock": false
},
@ -267,11 +254,10 @@
"step": 0.1,
"suffix": "Hz",
"compactHeight": false,
"param": [
"pid",
"ch",
"ki"
],
"thermostat:set_param": {
"topic": "pid",
"field": "ki"
},
"tip": "Integral gain",
"lock": false
},
@ -282,11 +268,10 @@
"step": 0.1,
"suffix": "s",
"compactHeight": false,
"param": [
"pid",
"ch",
"kd"
],
"thermostat:set_param": {
"topic": "pid",
"field": "kd"
},
"tip": "Differential gain",
"lock": false
},
@ -308,11 +293,10 @@
],
"decimals": 6,
"compactHeight": false,
"param": [
"pid",
"ch",
"output_min"
],
"thermostat:set_param": {
"topic": "pid",
"field": "output_min"
},
"tip": "Minimum PID output",
"lock": false
},
@ -327,11 +311,10 @@
],
"decimals": 6,
"compactHeight": false,
"param": [
"pid",
"ch",
"output_max"
],
"thermostat:set_param": {
"topic": "pid",
"field": "output_max"
},
"tip": "Maximum PID output",
"lock": false
}
@ -352,10 +335,9 @@
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"target_temp",
"ch"
],
"pid_autotune": {
"params_name": "target_temp"
},
"tip": "The target temperature to autotune for"
},
{
@ -367,13 +349,12 @@
"compactHeight": false,
"step": 100,
"limits": [
-2000,
0,
2000
],
"pid_autotune": [
"test_current",
"ch"
],
"pid_autotune": {
"params_name": "test_current"
},
"tip": "The testing current when autotuning"
},
{
@ -385,10 +366,9 @@
"prefix": "±",
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"temp_swing",
"ch"
],
"pid_autotune": {
"params_name": "temp_swing"
},
"tip": "The temperature swing around the target"
},
{
@ -399,10 +379,9 @@
"step": 0.1,
"format": "{value:.4f}",
"compactHeight": false,
"pid_autotune": [
"lookback",
"ch"
],
"pid_autotune": {
"params_name": "lookback"
},
"tip": "Amount of time to lookback"
},
{

View File

@ -266,36 +266,33 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes:
if change == "value":
if inner_param.opts.get("param", None) is not None:
new_value = data
if "thermostat:set_param" in inner_param.opts:
thermostat_param = inner_param.opts["thermostat:set_param"]
# Handle thermostat command irregularities
match inner_param.name(), new_value:
case "rate", "":
thermostat_param = thermostat_param.copy()
thermostat_param["field"] = "off"
case "control_method", "constant_current":
inner_param = inner_param.child("i_set")
thermostat_param = inner_param.opts["thermostat:set_param"]
new_value = inner_param.value()
case "control_method", "temperature_pid":
new_value = ""
if inner_param.opts.get("title", None).endswith(" (mA)"):
data /= 1000 # Given in mA
new_value /= 1000 # Given in mA
inner_param.setOpts(lock=True)
await self.client.set_param(
channel=ch, value=new_value, **thermostat_param
)
inner_param.setOpts(lock=False)
thermostat_param = inner_param.opts["param"]
if thermostat_param[1] == "ch":
thermostat_param[1] = ch
if inner_param.name() == "rate" and data is None:
set_param_args = (*thermostat_param[:2], "off")
else:
set_param_args = (*thermostat_param, data)
param.child(*param.childPath(inner_param)).setOpts(lock=True)
await self.client.set_param(*set_param_args)
param.child(*param.childPath(inner_param)).setOpts(lock=False)
if inner_param.opts.get("pid_autotune", None) is not None:
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(autotuner_param, ch, data)
if inner_param.opts.get("activaters", None) is not None:
activater = inner_param.opts["activaters"][
inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values
]
if activater is not None:
if activater[1] == "ch":
activater[1] = ch
await self.client.set_param(*activater)
if "pid_autotune" in inner_param.opts:
autotuner_param = inner_param.opts["pid_autotune"]
self.autotuners.set_params(ch=ch, val=new_value, **autotuner_param)
@asyncSlot()
async def pid_autotune_request(self, ch=0):