Skip to content

Commit

Permalink
feat: high resolution actor mode
Browse files Browse the repository at this point in the history
Note that this does not perform any checks on the size constraints.

Fixes #5
  • Loading branch information
Bloeckchengrafik committed Jan 7, 2024
1 parent 16d7514 commit 981f848
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 10 additions & 11 deletions swarm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
from swarm.swarm import *

from .serialhandler import SerialHandler
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion swarm/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 981f848

Please sign in to comment.