mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-23 01:41:54 +00:00
fix(dynamixel): store protocol_version and validate motor protocol
Persist protocol_version on DynamixelMotorsBus and add a MODEL_PROTOCOL table so motors that don't match the requested protocol (e.g. an AX motor on Protocol 2.0) are rejected at construction, mirroring Feetech.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user