Skip to content

Commit

Permalink
Use enumerator for the actuator packet ID (#1152)
Browse files Browse the repository at this point in the history
* Use enumerator for the actuator packet ID

* Fix tests
  • Loading branch information
cbrxyz authored Mar 6, 2024
1 parent e58b169 commit 444af15
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .handle import ActuatorBoard
from .packets import (
ActuatorPacketId,
ActuatorPollRequestPacket,
ActuatorPollResponsePacket,
ActuatorSetPacket,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
from dataclasses import dataclass
from enum import IntEnum

from mil_usb_to_can.sub9 import Packet


class ActuatorPacketId(IntEnum):
"""
Enumerator representing each controllable actuator.
"""

#: The dropper actuator.
DROPPER = 0
#: The torpedo launcher actuator.
TORPEDO_LAUNCHER = 1
#: The ball drop actuator. Only one actuator is used for both balls.
BALL_DROP = 2


@dataclass
class ActuatorSetPacket(Packet, msg_id=0x03, subclass_id=0x00, payload_format="BB"):
"""
Packet used by the actuator board to set a specific valve.
Attributes:
address (int): The actuator ID to set.
address (ActuatorPacketId): The actuator ID to set.
open (bool): Whether to open the specified actuator. ``True`` requests opening,
``False`` requests closing.
"""

address: int
address: ActuatorPacketId
open: bool


Expand All @@ -29,8 +43,6 @@ class ActuatorPollRequestPacket(
Packet used by the actuator board to request the status of all valves.
"""

pass


@dataclass
class ActuatorPollResponsePacket(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def test_correct_response(self):
self.assertFalse(self.get_srv(GetValveRequest(0)).opened)
self.assertTrue(self.set_srv(SetValveRequest(0, False)).success)
self.assertFalse(self.get_srv(GetValveRequest(0)).opened)
self.assertTrue(self.set_srv(SetValveRequest(3, True)).success)
self.assertTrue(self.get_srv(GetValveRequest(3)).opened)
self.assertTrue(self.set_srv(SetValveRequest(1, True)).success)
self.assertTrue(self.get_srv(GetValveRequest(1)).opened)
self.assertFalse(self.get_srv(GetValveRequest(0)).opened)
self.assertTrue(self.set_srv(SetValveRequest(4, False)).success)
self.assertFalse(self.get_srv(GetValveRequest(4)).opened)
self.assertTrue(self.set_srv(SetValveRequest(2, False)).success)
self.assertFalse(self.get_srv(GetValveRequest(2)).opened)
self.assertFalse(self.get_srv(GetValveRequest(0)).opened)


Expand Down
5 changes: 5 additions & 0 deletions docs/subjugator/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ ActuatorBoardSimulation
.. autoclass:: sub_actuator_board.ActuatorBoardSimulation
:members:

ActuatorPacketId
^^^^^^^^^^^^^^^^
.. autoclass:: sub_actuator_board.ActuatorPacketId
:members:

ActuatorSetPacket
^^^^^^^^^^^^^^^^^
.. attributetable:: sub_actuator_board.ActuatorSetPacket
Expand Down

0 comments on commit 444af15

Please sign in to comment.