From 981f848a7431f0ea3a69e57ce64cc2c81ac63fea Mon Sep 17 00:00:00 2001 From: Christian Bergschneider Date: Sun, 7 Jan 2024 02:16:04 +0100 Subject: [PATCH] feat: high resolution actor mode Note that this does not perform any checks on the size constraints. Fixes #5 --- swarm/__init__.py | 21 ++++++++++----------- swarm/swarm.py | 6 +++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/swarm/__init__.py b/swarm/__init__.py index ec2295e..3d08ca4 100644 --- a/swarm/__init__.py +++ b/swarm/__init__.py @@ -1,5 +1,4 @@ import asyncio -import logging from swarm.swarm import * from .serialhandler import SerialHandler @@ -98,20 +97,20 @@ async def get_thermometer(self, port_name: str) -> FtSwarmThermometer: async def get_ldr(self, port_name: str) -> FtSwarmLDR: return await self._get_object(port_name, FtSwarmLDR) - async def get_motor(self, port_name: str) -> FtSwarmMotor: - return await self._get_object(port_name, FtSwarmMotor) + async def get_motor(self, port_name: str, high_precision: bool = False) -> FtSwarmMotor: + return await self._get_object(port_name, FtSwarmMotor, high_precision) - async def get_tractor_motor(self, port_name: str) -> FtSwarmTractorMotor: - return await self._get_object(port_name, FtSwarmTractorMotor) + async def get_tractor_motor(self, port_name: str, high_precision: bool = False) -> FtSwarmTractorMotor: + return await self._get_object(port_name, FtSwarmTractorMotor, high_precision) - async def get_xm_motor(self, port_name: str) -> FtSwarmXMMotor: - return await self._get_object(port_name, FtSwarmXMMotor) + async def get_xm_motor(self, port_name: str, high_precision: bool = False) -> FtSwarmXMMotor: + return await self._get_object(port_name, FtSwarmXMMotor, high_precision) - async def get_encoder_motor(self, port_name: str) -> FtSwarmEncoderMotor: - return await self._get_object(port_name, FtSwarmEncoderMotor) + async def get_encoder_motor(self, port_name: str, high_precision: bool = False) -> FtSwarmEncoderMotor: + return await self._get_object(port_name, FtSwarmEncoderMotor, high_precision) - async def get_lamp(self, port_name: str) -> FtSwarmLamp: - return await self._get_object(port_name, FtSwarmLamp) + async def get_lamp(self, port_name: str, high_precision: bool = False) -> FtSwarmLamp: + return await self._get_object(port_name, FtSwarmLamp, high_precision) async def get_valve(self, port_name: str) -> FtSwarmValve: return await self._get_object(port_name, FtSwarmValve) diff --git a/swarm/swarm.py b/swarm/swarm.py index aeef380..ac1115c 100644 --- a/swarm/swarm.py +++ b/swarm/swarm.py @@ -290,8 +290,12 @@ class FtSwarmActor(FtSwarmIO): Don't use this class directly, use one of the derived classes instead """ + def __init__(self, swarm: FtSwarmBase, port_name: str, high_precision: bool = False) -> None: + super().__init__(swarm, port_name) + self._high_precision = high_precision + async def post_init(self) -> None: - await self._swarm.send(self._port_name, "setActorType", await self.get_actor_type()) + await self._swarm.send(self._port_name, "setActorType", await self.get_actor_type(), self._high_precision) async def get_actor_type(self) -> Actor: return Actor.UNDEFINDED