From 470ea9edb3ac067b8c1abcc56455e86fb4507eed Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 12 Oct 2023 13:13:12 +0800 Subject: [PATCH] Put PID output min and max into its own section The critical difference between this and the max_i_pos, max_i_neg pair is that output_max and output_min can have the same sign, meaning that it is possible that PID current can be limited to positive values only. --- pytec/tec_qt.py | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index a29719e..d29e10f 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -72,10 +72,6 @@ registerParameterType('mutex', MutexParameter) class WrappedClient(QObject, Client): connection_error = pyqtSignal() - async def start_session(self, *args, **kwargs): - await super().start_session(*args, **kwargs) - await self._sync_pwm_pid_limits() - async def _read_line(self): try: return await super()._read_line() @@ -83,25 +79,6 @@ class WrappedClient(QObject, Client): logging.error("Client connection error, disconnecting", exc_info=True) self.connection_error.emit() - async def _sync_pwm_pid_limits(self): - pwm_report = await self.get_pwm() - pid_report = await self.get_pid() - for pwm_channel, pid_channel in zip(pwm_report, pid_report): - ch = pwm_channel['channel'] - if (pwm_limit := pwm_channel['max_i_pos']['value']) != (pid_limit := pid_channel['parameters']['output_max']): - # Set the minimum of the 2 - if pwm_limit < pid_limit: - await self.set_param('pid', ch, 'output_max', pwm_limit) - else: - await self.set_param('pwm', ch, 'max_i_pos', pid_limit) - - if (pwm_limit := -pwm_channel['max_i_neg']['value']) != (pid_limit := pid_channel['parameters']['output_min']): - # Set the minimum of the 2 - if pwm_limit < pid_limit: - await self.set_param('pid', ch, 'output_min', pwm_limit) - else: - await self.set_param('pwm', ch, 'max_i_neg', -pid_limit) - class ClientWatcher(QObject): fan_update = pyqtSignal(dict) @@ -244,9 +221,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): ]}, {'name': 'Limits', 'expanded': False, 'type': 'group', 'children': [ {'name': 'Max Current', 'type': 'float', 'value': 0, 'step': 100, 'decimals': 6, 'limits': (0, 3000), - 'suffix': 'mA', 'param': [('pwm', ch, 'max_i_pos'), ('pid', ch, 'output_max')]}, + 'suffix': 'mA', 'param': [('pwm', ch, 'max_i_pos')]}, {'name': 'Min Current', 'type': 'float', 'value': 0, 'step': 100, 'decimals': 6, 'limits': (-3000, 0), - 'suffix': 'mA', 'param': [('pwm', ch, 'max_i_neg', '-'), ('pid', ch, 'output_min')]}, + 'suffix': 'mA', 'param': [('pwm', ch, 'max_i_neg', '-')]}, {'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True, 'suffix': 'V', 'param': [('pwm', ch, 'max_v')]}, ]} @@ -266,6 +243,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): {'name': 'Kp', 'type': 'float', 'step': 0.1, 'suffix': '', 'param': [('pid', ch, 'kp')]}, {'name': 'Ki', 'type': 'float', 'step': 0.1, 'suffix': 'Hz', 'param': [('pid', ch, 'ki')]}, {'name': 'Kd', 'type': 'float', 'step': 0.1, 'suffix': 's', 'param': [('pid', ch, 'kd')]}, + {'name': 'Max Current Output', 'type': 'float', 'step': 100, 'limits': (-3000, 3000), 'decimals': 6, 'suffix': 'mA', 'param': [('pid', ch, 'output_max')]}, + {'name': 'Min Current Output', 'type': 'float', 'step': 100, 'limits': (-3000, 3000), 'decimals': 6, 'suffix': 'mA', 'param': [('pid', ch, 'output_min')]}, {'name': 'PID Auto Tune', 'expanded': False, 'type': 'group', 'children': [ {'name': 'Target Temperature', 'type': 'float', 'value': 20, 'step': 0.1, 'suffix': '°C'}, {'name': 'Test Current', 'type': 'float', 'value': 1000, 'decimals': 6, 'step': 100, 'limits': (-3000, 3000), 'suffix': 'mA'}, @@ -807,6 +786,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"]) + self.params[channel].child("PID Config", "Max Current Output").setValue(settings["parameters"]["output_max"] * 1000) + self.params[channel].child("PID Config", "Min Current Output").setValue(settings["parameters"]["output_min"] * 1000) self.params[channel].child("Output Config", "Control Method", "Set Temperature").setValue(settings["target"]) self.channel_graphs[channel].t_line.setValue(round(settings["target"], 6))