diff --git a/asitiger/command.py b/asitiger/command.py index 00f0a56..209c9c7 100644 --- a/asitiger/command.py +++ b/asitiger/command.py @@ -14,6 +14,7 @@ class Command: MOVE = "M" MOVREL = "R" RDSTAT = "RS" + SECURE = "SECURE" SETHOME = "HM" SPEED = "S" STATUS = "/" diff --git a/asitiger/secure.py b/asitiger/secure.py new file mode 100644 index 0000000..446b8d0 --- /dev/null +++ b/asitiger/secure.py @@ -0,0 +1,14 @@ +from enum import Enum +from typing import Union + + +class SecurePosition(Enum): + LOCKED = 0 + UNLOCKED = 1 + + @classmethod + def resolve_value(cls, position: Union["SecurePosition", int, float]): + if isinstance(position, cls): + return position.value + + return position diff --git a/asitiger/tigercontroller.py b/asitiger/tigercontroller.py index 75927a6..afc1465 100644 --- a/asitiger/tigercontroller.py +++ b/asitiger/tigercontroller.py @@ -5,6 +5,7 @@ from asitiger.axis import Axis from asitiger.command import Command from asitiger.errors import Errors +from asitiger.secure import SecurePosition from asitiger.serialconnection import SerialConnection from asitiger.status import AxisStatus, Status, statuses_for_rdstat @@ -73,6 +74,13 @@ def enable_axes(self, axes: List[str]): def disable_axes(self, axes: List[str]): self.motor_control({axis: "-" for axis in axes}) + def set_plate_lock( + self, position: Union[SecurePosition, float], card_address: int = None + ): + return self.secure( + {"X": SecurePosition.resolve_value(position)}, card_address=card_address + ) + # The methods below map directly onto the Tiger serial API methods def build(self, card_address: int = None) -> List[str]: @@ -112,6 +120,13 @@ def rdstat(self, axes: List[str]) -> List[Union[AxisStatus, Status]]: response = self.send_command(f"{Command.RDSTAT} {' '.join(axes)}") return statuses_for_rdstat(response) + def secure( + self, settings: Dict[str, Union[int, float, str]], card_address: int = None, + ): + self.send_command( + Command.format(Command.SECURE, settings, card_address=card_address) + ) + def set_home(self, axes: Dict[str, Union[str, int]]) -> str: return self.send_command( Command.format(Command.SETHOME, coordinates=axes, flag_overrides=["+"])