This commit is contained in:
atse 2023-10-12 10:50:56 +08:00
parent 2e8b26eb60
commit 83c14fb2de
1 changed files with 19 additions and 4 deletions

View File

@ -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):