Add support for feetech protocol 1 to _split_into_byte_chunks
This commit is contained in:
@@ -67,43 +67,16 @@ def test_autouse_patch():
|
||||
(0x12, 1, [0x12]),
|
||||
(0x1234, 2, [0x34, 0x12]),
|
||||
(0x12345678, 4, [0x78, 0x56, 0x34, 0x12]),
|
||||
(0, 1, [0x00]),
|
||||
(0, 2, [0x00, 0x00]),
|
||||
(0, 4, [0x00, 0x00, 0x00, 0x00]),
|
||||
(255, 1, [0xFF]),
|
||||
(65535, 2, [0xFF, 0xFF]),
|
||||
(4294967295, 4, [0xFF, 0xFF, 0xFF, 0xFF]),
|
||||
],
|
||||
ids=[
|
||||
"1 byte",
|
||||
"2 bytes",
|
||||
"4 bytes",
|
||||
"0 with 1 byte",
|
||||
"0 with 2 bytes",
|
||||
"0 with 4 bytes",
|
||||
"max single byte",
|
||||
"max two bytes",
|
||||
"max four bytes",
|
||||
],
|
||||
) # fmt: skip
|
||||
def test_serialize_data(value, length, expected):
|
||||
assert DynamixelMotorsBus._serialize_data(value, length) == expected
|
||||
|
||||
|
||||
def test_serialize_data_invalid_length():
|
||||
with pytest.raises(NotImplementedError):
|
||||
DynamixelMotorsBus._serialize_data(100, 3)
|
||||
|
||||
|
||||
def test_serialize_data_negative_numbers():
|
||||
with pytest.raises(ValueError):
|
||||
neg = DynamixelMotorsBus._serialize_data(-1, 1)
|
||||
print(neg)
|
||||
|
||||
|
||||
def test_serialize_data_large_number():
|
||||
with pytest.raises(ValueError):
|
||||
DynamixelMotorsBus._serialize_data(2**32, 4) # 4-byte max is 0xFFFFFFFF
|
||||
def test__split_into_byte_chunks(value, length, expected):
|
||||
bus = DynamixelMotorsBus("", {})
|
||||
assert bus._split_into_byte_chunks(value, length) == expected
|
||||
|
||||
|
||||
def test_abc_implementation(dummy_motors):
|
||||
|
||||
@@ -61,48 +61,27 @@ def test_autouse_patch():
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value, length, expected",
|
||||
"protocol, value, length, expected",
|
||||
[
|
||||
(0x12, 1, [0x12]),
|
||||
(0x1234, 2, [0x34, 0x12]),
|
||||
(0x12345678, 4, [0x78, 0x56, 0x34, 0x12]),
|
||||
(0, 1, [0x00]),
|
||||
(0, 2, [0x00, 0x00]),
|
||||
(0, 4, [0x00, 0x00, 0x00, 0x00]),
|
||||
(255, 1, [0xFF]),
|
||||
(65535, 2, [0xFF, 0xFF]),
|
||||
(4294967295, 4, [0xFF, 0xFF, 0xFF, 0xFF]),
|
||||
(0, 0x12, 1, [0x12]),
|
||||
(1, 0x12, 1, [0x12]),
|
||||
(0, 0x1234, 2, [0x34, 0x12]),
|
||||
(1, 0x1234, 2, [0x12, 0x34]),
|
||||
(0, 0x12345678, 4, [0x78, 0x56, 0x34, 0x12]),
|
||||
(1, 0x12345678, 4, [0x56, 0x78, 0x12, 0x34]),
|
||||
],
|
||||
ids=[
|
||||
"1 byte",
|
||||
"2 bytes",
|
||||
"4 bytes",
|
||||
"0 with 1 byte",
|
||||
"0 with 2 bytes",
|
||||
"0 with 4 bytes",
|
||||
"max single byte",
|
||||
"max two bytes",
|
||||
"max four bytes",
|
||||
"P0: 1 byte",
|
||||
"P1: 1 byte",
|
||||
"P0: 2 bytes",
|
||||
"P1: 2 bytes",
|
||||
"P0: 4 bytes",
|
||||
"P1: 4 bytes",
|
||||
],
|
||||
) # fmt: skip
|
||||
def test_serialize_data(value, length, expected):
|
||||
assert FeetechMotorsBus._serialize_data(value, length) == expected
|
||||
|
||||
|
||||
def test_serialize_data_invalid_length():
|
||||
with pytest.raises(NotImplementedError):
|
||||
FeetechMotorsBus._serialize_data(100, 3)
|
||||
|
||||
|
||||
def test_serialize_data_negative_numbers():
|
||||
with pytest.raises(ValueError):
|
||||
neg = FeetechMotorsBus._serialize_data(-1, 1)
|
||||
print(neg)
|
||||
|
||||
|
||||
def test_serialize_data_large_number():
|
||||
with pytest.raises(ValueError):
|
||||
FeetechMotorsBus._serialize_data(2**32, 4) # 4-byte max is 0xFFFFFFFF
|
||||
def test__split_into_byte_chunks(protocol, value, length, expected):
|
||||
bus = FeetechMotorsBus("", {}, protocol_version=protocol)
|
||||
assert bus._split_into_byte_chunks(value, length) == expected
|
||||
|
||||
|
||||
def test_abc_implementation(dummy_motors):
|
||||
|
||||
@@ -2,12 +2,50 @@ import re
|
||||
|
||||
import pytest
|
||||
|
||||
from lerobot.common.motors.motors_bus import assert_same_address, get_address, get_ctrl_table
|
||||
from lerobot.common.motors.motors_bus import (
|
||||
Motor,
|
||||
MotorsBus,
|
||||
assert_same_address,
|
||||
get_address,
|
||||
get_ctrl_table,
|
||||
)
|
||||
|
||||
# TODO(aliberts)
|
||||
# class DummyMotorsBus(MotorsBus):
|
||||
# def __init__(self, port: str, motors: dict[str, Motor]):
|
||||
# super().__init__(port, motors)
|
||||
DUMMY_CTRL_TABLE = {"Present_Position": (13, 4)}
|
||||
|
||||
DUMMY_BAUDRATE_TABLE = {
|
||||
0: 1_000_000,
|
||||
1: 500_000,
|
||||
}
|
||||
|
||||
DUMMY_ENCODING_TABLE = {
|
||||
"Present_Position": 8,
|
||||
}
|
||||
|
||||
DUMMY_MODEL_NUMBER_TABLE = {""}
|
||||
|
||||
|
||||
class DummyMotorsBus(MotorsBus):
|
||||
available_baudrates = [1_000_000]
|
||||
default_timeout = 1000
|
||||
model_baudrate_table = {"model": DUMMY_BAUDRATE_TABLE}
|
||||
model_ctrl_table = {"model": DUMMY_CTRL_TABLE}
|
||||
model_encoding_table = {"model": DUMMY_ENCODING_TABLE}
|
||||
model_number_table = {"model": 1234}
|
||||
model_resolution_table = {"model": 4096}
|
||||
normalized_data = ["Present_Position"]
|
||||
|
||||
def __init__(self, port: str, motors: dict[str, Motor]):
|
||||
super().__init__(port, motors)
|
||||
|
||||
def _assert_protocol_is_compatible(self, instruction_name): ...
|
||||
def configure_motors(self): ...
|
||||
def disable_torque(self, motors): ...
|
||||
def enable_torque(self, motors): ...
|
||||
def _get_half_turn_homings(self, positions): ...
|
||||
def _encode_sign(self, data_name, ids_values): ...
|
||||
def _decode_sign(self, data_name, ids_values): ...
|
||||
def _split_into_byte_chunks(self, value, length): ...
|
||||
def broadcast_ping(self, num_retry, raise_on_error): ...
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -85,3 +123,21 @@ def test_assert_same_address_different_bytes(model_ctrl_table):
|
||||
match=re.escape("At least two motor models use a different bytes representation"),
|
||||
):
|
||||
assert_same_address(model_ctrl_table, models, "Goal_Position")
|
||||
|
||||
|
||||
def test__serialize_data_invalid_length():
|
||||
bus = DummyMotorsBus("", {})
|
||||
with pytest.raises(NotImplementedError):
|
||||
bus._serialize_data(100, 3)
|
||||
|
||||
|
||||
def test__serialize_data_negative_numbers():
|
||||
bus = DummyMotorsBus("", {})
|
||||
with pytest.raises(ValueError):
|
||||
bus._serialize_data(-1, 1)
|
||||
|
||||
|
||||
def test__serialize_data_large_number():
|
||||
bus = DummyMotorsBus("", {})
|
||||
with pytest.raises(ValueError):
|
||||
bus._serialize_data(2**32, 4) # 4-byte max is 0xFFFFFFFF
|
||||
|
||||
Reference in New Issue
Block a user