From be77a6f205544e090f854e525d7c0d401fb7f1c7 Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 12:57:42 +0800 Subject: [PATCH 1/6] send_command: Use `in` syntax --- pytec/tec_qt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 2393d0a..e6172b2 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -266,7 +266,7 @@ class MainWindow(QtWidgets.QMainWindow): for inner_param, change, data in changes: if change == "value": - if inner_param.opts.get("param", None) is not None: + if "param" in inner_param.opts: if inner_param.opts.get("suffix", None) == "mA": data /= 1000 # Given in mA @@ -282,13 +282,13 @@ class MainWindow(QtWidgets.QMainWindow): 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: + if "pid_autotune" in inner_param.opts: auto_tuner_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) - if inner_param.opts.get("activaters", None) is not None: + if "activaters" in inner_param.opts: activater = inner_param.opts["activaters"][ inner_param.opts["limits"].index(data) ] -- 2.44.1 From d57cc9ef2a99dc787300af429f3603980bda9b50 Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 12:58:29 +0800 Subject: [PATCH 2/6] send_command: Alias `data` as `new_value` --- pytec/tec_qt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index e6172b2..db81e1c 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -266,18 +266,19 @@ class MainWindow(QtWidgets.QMainWindow): for inner_param, change, data in changes: if change == "value": + new_value = data if "param" in inner_param.opts: if inner_param.opts.get("suffix", None) == "mA": - data /= 1000 # Given in mA + new_value /= 1000 # Given in mA thermostat_param = inner_param.opts["param"] if thermostat_param[1] == "ch": thermostat_param[1] = ch - if inner_param.name() == "Postfilter Rate" and data is None: + if inner_param.name() == "Postfilter Rate" and new_value is None: set_param_args = (*thermostat_param[:2], "off") else: - set_param_args = (*thermostat_param, data) + set_param_args = (*thermostat_param, new_value) 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) @@ -286,7 +287,7 @@ class MainWindow(QtWidgets.QMainWindow): auto_tuner_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(auto_tuner_param, ch, new_value) if "activaters" in inner_param.opts: activater = inner_param.opts["activaters"][ -- 2.44.1 From dd83daa5d9804583d17bffe0208c70a361e32021 Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 12:58:58 +0800 Subject: [PATCH 3/6] send_command: Remove indirect path to parameter The child at inner_param's childpath to the root parameter... is just inner_param itself. --- pytec/tec_qt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index db81e1c..2e60e1d 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -279,9 +279,9 @@ class MainWindow(QtWidgets.QMainWindow): set_param_args = (*thermostat_param[:2], "off") else: set_param_args = (*thermostat_param, new_value) - param.child(*param.childPath(inner_param)).setOpts(lock=True) + inner_param.setOpts(lock=True) await self.client.set_param(*set_param_args) - param.child(*param.childPath(inner_param)).setOpts(lock=False) + inner_param.setOpts(lock=False) if "pid_autotune" in inner_param.opts: auto_tuner_param = inner_param.opts["pid_autotune"][0] -- 2.44.1 From 278898fad2883819cd22c2222ae80ed9c81e4649 Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 13:13:43 +0800 Subject: [PATCH 4/6] send_command: Switch to thermostat:set_param Use a `dict` to map values to thermostat parameters, which correspond to the `set_param` parameters in the pytec client. New tag "thermostat:set_param" used in JSON. --- pytec/pytec/gui/view/param_tree.json | 126 ++++++++++++--------------- pytec/tec_qt.py | 17 ++-- 2 files changed, 65 insertions(+), 78 deletions(-) diff --git a/pytec/pytec/gui/view/param_tree.json b/pytec/pytec/gui/view/param_tree.json index e495b84..bf490dc 100644 --- a/pytec/pytec/gui/view/param_tree.json +++ b/pytec/pytec/gui/view/param_tree.json @@ -46,11 +46,10 @@ "triggerOnShow":true, "decimals":6, "suffix":"mA", - "param":[ - "pwm", - "ch", - "i_set" - ], + "thermostat:set_param":{ + "topic":"pwm", + "field":"i_set" + }, "lock":false }, { @@ -63,11 +62,10 @@ 300 ], "format":"{value:.4f} °C", - "param":[ - "pid", - "ch", - "target" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"target" + }, "lock":false } ] @@ -88,11 +86,10 @@ 2000 ], "suffix":"mA", - "param":[ - "pwm", - "ch", - "max_i_pos" - ], + "thermostat:set_param":{ + "topic":"pwm", + "field":"max_i_pos" + }, "lock":false }, { @@ -106,11 +103,10 @@ 2000 ], "suffix":"mA", - "param":[ - "pwm", - "ch", - "max_i_neg" - ], + "thermostat:set_param":{ + "topic":"pwm", + "field":"max_i_neg" + }, "lock":false }, { @@ -124,11 +120,10 @@ ], "siPrefix":true, "suffix":"V", - "param":[ - "pwm", - "ch", - "max_v" - ], + "thermostat:set_param":{ + "topic":"pwm", + "field":"max_v" + }, "lock":false } ] @@ -150,11 +145,10 @@ 100 ], "format":"{value:.4f} °C", - "param":[ - "s-h", - "ch", - "t0" - ], + "thermostat:set_param":{ + "topic":"s-h", + "field":"t0" + }, "lock":false }, { @@ -164,11 +158,10 @@ "step":1, "siPrefix":true, "suffix":"Ω", - "param":[ - "s-h", - "ch", - "r0" - ], + "thermostat:set_param":{ + "topic":"s-h", + "field":"r0" + }, "lock":false }, { @@ -178,22 +171,20 @@ "step":1, "suffix":"K", "decimals":4, - "param":[ - "s-h", - "ch", - "b" - ], + "thermostat:set_param":{ + "topic":"s-h", + "field":"b" + }, "lock":false }, { "name":"Postfilter Rate", "type":"list", "value":16.67, - "param":[ - "postfilter", - "ch", - "rate" - ], + "thermostat:set_param":{ + "topic":"postfilter", + "field":"rate" + }, "limits":{ "Off":null, "16.67 Hz":16.67, @@ -215,11 +206,10 @@ "type":"float", "step":0.1, "suffix":"", - "param":[ - "pid", - "ch", - "kp" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"kp" + }, "lock":false }, { @@ -227,11 +217,10 @@ "type":"float", "step":0.1, "suffix":"Hz", - "param":[ - "pid", - "ch", - "ki" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"ki" + }, "lock":false }, { @@ -239,11 +228,10 @@ "type":"float", "step":0.1, "suffix":"s", - "param":[ - "pid", - "ch", - "kd" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"kd" + }, "lock":false }, { @@ -261,11 +249,10 @@ ], "decimals":6, "suffix":"mA", - "param":[ - "pid", - "ch", - "output_min" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"output_min" + }, "lock":false }, { @@ -278,11 +265,10 @@ ], "decimals":6, "suffix":"mA", - "param":[ - "pid", - "ch", - "output_max" - ], + "thermostat:set_param":{ + "topic":"pid", + "field":"output_max" + }, "lock":false } ] diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 2e60e1d..bb9f60e 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -267,20 +267,21 @@ class MainWindow(QtWidgets.QMainWindow): for inner_param, change, data in changes: if change == "value": new_value = data - if "param" in inner_param.opts: + if "thermostat:set_param" in inner_param.opts: if inner_param.opts.get("suffix", None) == "mA": new_value /= 1000 # Given in mA - thermostat_param = inner_param.opts["param"] - if thermostat_param[1] == "ch": - thermostat_param[1] = ch + thermostat_param = inner_param.opts["thermostat:set_param"] if inner_param.name() == "Postfilter Rate" and new_value is None: - set_param_args = (*thermostat_param[:2], "off") - else: - set_param_args = (*thermostat_param, new_value) + thermostat_param = thermostat_param.copy() + thermostat_param["field"] = "off" + new_value = "" + inner_param.setOpts(lock=True) - await self.client.set_param(*set_param_args) + await self.client.set_param( + channel=ch, value=new_value, **thermostat_param + ) inner_param.setOpts(lock=False) if "pid_autotune" in inner_param.opts: -- 2.44.1 From 5c8d9c7cce56598b955c0a1d01b0fab056d38a3b Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 13:14:44 +0800 Subject: [PATCH 5/6] send_command: Simplify "pid_autotune" parameters --- pytec/pytec/gui/view/param_tree.json | 20 ++++---------------- pytec/tec_qt.py | 4 +--- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/pytec/pytec/gui/view/param_tree.json b/pytec/pytec/gui/view/param_tree.json index bf490dc..fff0a0d 100644 --- a/pytec/pytec/gui/view/param_tree.json +++ b/pytec/pytec/gui/view/param_tree.json @@ -284,10 +284,7 @@ "value":20, "step":0.1, "format":"{value:.4f} °C", - "pid_autotune":[ - "target_temp", - "ch" - ] + "pid_autotune":"target_temp" }, { "name":"Test Current", @@ -300,10 +297,7 @@ 2000 ], "suffix":"mA", - "pid_autotune":[ - "test_current", - "ch" - ] + "pid_autotune":"test_current" }, { "name":"Temperature Swing", @@ -312,10 +306,7 @@ "step":0.1, "prefix":"±", "format":"{value:.4f} °C", - "pid_autotune":[ - "temp_swing", - "ch" - ] + "pid_autotune":"temp_swing" }, { "name":"Lookback", @@ -323,10 +314,7 @@ "value":3.0, "step":0.1, "format":"{value:.4f} s", - "pid_autotune":[ - "lookback", - "ch" - ] + "pid_autotune":"lookback" }, { "name":"Run", diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index bb9f60e..70103fa 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -285,9 +285,7 @@ class MainWindow(QtWidgets.QMainWindow): inner_param.setOpts(lock=False) if "pid_autotune" in inner_param.opts: - auto_tuner_param = inner_param.opts["pid_autotune"][0] - if inner_param.opts["pid_autotune"][1] != "ch": - ch = inner_param.opts["pid_autotune"][1] + auto_tuner_param = inner_param.opts["pid_autotune"] self.autotuners.set_params(auto_tuner_param, ch, new_value) if "activaters" in inner_param.opts: -- 2.44.1 From 41abad7aa38db1dee7907d42030412c15d86e9dc Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 14 Aug 2024 13:15:19 +0800 Subject: [PATCH 6/6] send_command: Remove "activater" Interpret commands anomalies directly in send_command instead --- pytec/pytec/gui/view/param_tree.json | 12 ++++-------- pytec/tec_qt.py | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/pytec/pytec/gui/view/param_tree.json b/pytec/pytec/gui/view/param_tree.json index fff0a0d..28ce704 100644 --- a/pytec/pytec/gui/view/param_tree.json +++ b/pytec/pytec/gui/view/param_tree.json @@ -25,14 +25,10 @@ "Constant Current", "Temperature PID" ], - "activaters":[ - null, - [ - "pwm", - "ch", - "pid" - ] - ], + "thermostat:set_param":{ + "topic":"pwm", + "field":"pid" + }, "children":[ { "name":"Set Current", diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 70103fa..c760d88 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -273,10 +273,16 @@ class MainWindow(QtWidgets.QMainWindow): thermostat_param = inner_param.opts["thermostat:set_param"] - if inner_param.name() == "Postfilter Rate" and new_value is None: - thermostat_param = thermostat_param.copy() - thermostat_param["field"] = "off" - new_value = "" + # Handle thermostat command irregularities + match inner_param.name(), new_value: + case "Postfilter Rate", None: + thermostat_param = thermostat_param.copy() + thermostat_param["field"] = "off" + new_value = "" + case "Control Method", "Constant Current": + return + case "Control Method", "Temperature PID": + new_value = "" inner_param.setOpts(lock=True) await self.client.set_param( @@ -288,15 +294,6 @@ class MainWindow(QtWidgets.QMainWindow): auto_tuner_param = inner_param.opts["pid_autotune"] self.autotuners.set_params(auto_tuner_param, ch, new_value) - if "activaters" in inner_param.opts: - activater = inner_param.opts["activaters"][ - inner_param.opts["limits"].index(data) - ] - if activater is not None: - if activater[1] == "ch": - activater[1] = ch - await self.client.set_param(*activater) - @asyncSlot() async def pid_auto_tune_request(self, ch=0): match self.autotuners.get_state(ch): -- 2.44.1