From 7f7f749e84b23094572bea7dd8329b5a555143e5 Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 22 Aug 2023 13:22:07 +0800 Subject: [PATCH] Interface change --- pytec/tec_qt.py | 51 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 867a6c3..d714252 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -125,19 +125,23 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """Thermostat parameters that are particular to a channel""" THERMOSTAT_PARAMETERS = [[ - {'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True, - 'suffix': 'A', 'param': [('pwm', ch, 'i_set')]}, - {'name': 'Temperature PID', 'type': 'bool', 'value': False, 'commands': [f'pwm {ch} pid'], - 'children': [ - {'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), 'siPrefix': True, - 'suffix': '°C', 'param': [('pid', ch, 'target')]}, - ]}, - {'name': 'Output Config', 'expanded': False, 'type': 'group', 'children': [ - {'name': 'Max Absolute Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True, - 'suffix': 'A', 'commands': [f'pwm {ch} max_i_pos {{value}}', f'pwm {ch} max_i_neg {{value}}', - f'pid {ch} output_min -{{value}}', f'pid {ch} output_max {{value}}']}, - {'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True, - 'suffix': 'V', 'param': [('pwm', ch, 'max_v')]}, + {'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True}, + {'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True}, + {'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [ + {'name': 'Control Method', 'type': 'list', 'limits': {'Current Setpoint': False, 'Temperature PID': True}, + 'commands': [f'pwm {ch} pid'], 'children': [ + {'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True, + 'suffix': 'A', 'param': [('pwm', ch, 'i_set')]}, + {'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), 'siPrefix': True, + 'suffix': '°C', 'param': [('pid', ch, 'target')]}, + ]}, + {'name': 'Limits', 'expanded': False, 'type': 'group', 'children': [ + {'name': 'Max Absolute Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True, + 'suffix': 'A', 'commands': [f'pwm {ch} max_i_pos {{value}}', f'pwm {ch} max_i_neg {{value}}', + f'pid {ch} output_min -{{value}}', f'pid {ch} output_max {{value}}']}, + {'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True, + 'suffix': 'V', 'param': [('pwm', ch, 'max_v')]}, + ]} ]}, {'name': 'Thermistor Config', 'expanded': False, 'type': 'group', 'children': [ {'name': 'T₀', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-100, 100), 'siPrefix': True, @@ -585,13 +589,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): if inner_param.opts.get("commands", None) is not None: ch = param.value() match inner_param.name(): - case 'Temperature PID': + case 'Control Method': pid_enabled = data getattr(self, f'ch{ch}_t_line').setVisible(pid_enabled) if pid_enabled: getattr(self, f'ch{ch}_t_line').setValue(inner_param.child('Set Temperature').value()) else: - await self.client.set_param('pwm', ch, 'i_set', param.child('Constant Current').value()) + await self.client.set_param('pwm', ch, 'i_set', inner_param.child('Constant Current').value()) return case 'Set Temperature': getattr(self, f'ch{ch}_t_line').setValue(data) @@ -614,8 +618,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.params[channel].child("PID Config", "Kp").setValue(settings["parameters"]["kp"]) self.params[channel].child("PID Config", "Ki").setValue(settings["parameters"]["ki"]) self.params[channel].child("PID Config", "Kd").setValue(settings["parameters"]["kd"]) - if self.params[channel].child("Temperature PID").value(): - self.params[channel].child("Temperature PID", "Set Temperature").setValue(settings["target"]) + if self.params[channel].child("Output Config", "Control Method").value(): + self.params[channel].child("Output Config", "Control Method", "Set Temperature").setValue(settings["target"]) getattr(self, f'ch{channel}_t_line').setValue(settings["target"]) @pyqtSlot(list) @@ -623,10 +627,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): for settings in report_data: channel = settings["channel"] with QSignalBlocker(self.params[channel]): - self.params[channel].child("Temperature PID").setValue(settings["pid_engaged"]) + self.params[channel].child("Output Config", "Control Method").setValue(settings["pid_engaged"]) getattr(self, f'ch{channel}_t_line').setVisible(settings["pid_engaged"]) - if not settings["pid_engaged"]: - self.params[channel].child("Constant Current").setValue(settings["i_set"]) + self.params[channel].child("Output Config", "Control Method", "Constant Current").setValue(settings["i_set"]) + if settings['temperature'] is not None: + self.params[channel].child("Temperature").setValue(settings['temperature']) + if settings['tec_i'] is not None: + self.params[channel].child("Current through TEC").setValue(settings['tec_i']) @pyqtSlot(list) def update_thermistor(self, sh_data): @@ -642,8 +649,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): for pwm_params in pwm_data: channel = pwm_params["channel"] with QSignalBlocker(self.params[channel]): - self.params[channel].child("Output Config", "Max Absolute Voltage").setValue(pwm_params["max_v"]["value"]) - self.params[channel].child("Output Config", "Max Absolute Current").setValue(pwm_params["max_i_pos"]["value"]) + self.params[channel].child("Output Config", "Limits", "Max Absolute Voltage").setValue(pwm_params["max_v"]["value"]) + self.params[channel].child("Output Config", "Limits", "Max Absolute Current").setValue(pwm_params["max_i_pos"]["value"]) @pyqtSlot(list) def update_postfilter(self, postfilter_data):