diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 4f6019b..1e477a4 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -72,8 +72,9 @@ registerParameterType('mutex', MutexParameter) class WrappedClient(QObject, Client): connection_error = pyqtSignal() - def __init__(self, parent): - super().__init__(parent) + 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: @@ -82,10 +83,24 @@ class WrappedClient(QObject, Client): logging.error("Client connection error, disconnecting", exc_info=True) self.connection_error.emit() - async def _check_zero_limits(self): + async def _sync_pwm_pid_limits(self): pwm_report = await self.get_pwm() pid_report = await self.get_pid() - # TODO: Get pid output_max and max_i_pos synced. Same for min and neg. + 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):