diff --git a/src/lerobot/motors/dynamixel/dynamixel.py b/src/lerobot/motors/dynamixel/dynamixel.py index 4e2a6fd51..0365e42c3 100644 --- a/src/lerobot/motors/dynamixel/dynamixel.py +++ b/src/lerobot/motors/dynamixel/dynamixel.py @@ -33,6 +33,7 @@ from .tables import ( MODEL_CONTROL_TABLE, MODEL_ENCODING_TABLE, MODEL_NUMBER_TABLE, + MODEL_PROTOCOL, MODEL_RESOLUTION, ) @@ -117,6 +118,8 @@ class DynamixelMotorsBus(SerialMotorsBus): ): require_package("dynamixel-sdk", extra="dynamixel", import_name="dynamixel_sdk") super().__init__(port, motors, calibration) + self.protocol_version = protocol_version + self._assert_same_protocol() self.port_handler = dxl.PortHandler(self.port) self.packet_handler = dxl.PacketHandler(protocol_version) print(f"Using protocol version {protocol_version}") @@ -125,6 +128,14 @@ class DynamixelMotorsBus(SerialMotorsBus): self._comm_success = dxl.COMM_SUCCESS self._no_error = 0x00 + def _assert_same_protocol(self) -> None: + if any(MODEL_PROTOCOL[model] != self.protocol_version for model in self.models): + raise ValueError( + f"Some motors are incompatible with protocol_version={self.protocol_version}. " + f"Expected per-model protocols: " + f"{ {model: MODEL_PROTOCOL[model] for model in self.models} }" + ) + def _assert_protocol_is_compatible(self, instruction_name: str) -> None: pass diff --git a/src/lerobot/motors/dynamixel/tables.py b/src/lerobot/motors/dynamixel/tables.py index fc63e77ab..889242a21 100644 --- a/src/lerobot/motors/dynamixel/tables.py +++ b/src/lerobot/motors/dynamixel/tables.py @@ -247,6 +247,20 @@ MODEL_BAUDRATE_TABLE = { "ax-12a": AX_SERIES_BAUDRATE_TABLE, } +# {model: protocol_version} +# AX series communicate over Protocol 1.0, X series over Protocol 2.0. +MODEL_PROTOCOL = { + "x_series": 2, + "xl330-m077": 2, + "xl330-m288": 2, + "xl430-w250": 2, + "xm430-w350": 2, + "xm540-w270": 2, + "xc430-w150": 2, + "ax_series": 1, + "ax-12a": 1, +} + AVAILABLE_BAUDRATES = [ 9_600, 19_200,