Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions config/l1_hand.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"model": "L1-Hand-V1",
"name": "L1-Hand-V1",
"aliases": ["XiaoShun-Hand"],
"slave_id": 49,
"name": "GHand Lite 1",
"modbus_profile": "l1",
"ethercat_input_sizes": [1302],
"ethercat_output_size": 36,
"ethercat_rpdo_layout": "per_joint_mode_3reg",
"ethercat_tpdo_layout": "l1_extended",
"joints": [
{ "id": "THUMB_TMC_FE" },
{ "id": "THUMB_TMC_AA", "min": 0.0, "max": 30.0 },
Expand All @@ -21,6 +15,12 @@
{ "id": "LF_PIP" },
{ "id": "LF_MCP", "min": 0.0, "max": 90.0 }
],
"has_tactile": false,
"tactile_regions": []
"has_tactile": true,
"tactile_regions": [
{ "id": "THUMB", "count": 80 },
{ "id": "FF", "count": 80 },
{ "id": "MF", "count": 80 },
{ "id": "RF", "count": 80 },
{ "id": "LF", "count": 80 }
]
}
6 changes: 5 additions & 1 deletion src/ghand/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def find_config_by_name(device_name: str) -> ProductConfig | None:
except (json.JSONDecodeError, OSError):
continue

names = [data.get("name", ""), *data.get("aliases", [])]
names = [
data.get("model", ""),
data.get("name", ""),
*data.get("aliases", []),
]
if any(name.lower() == device_name.lower() for name in names if name):
logger.info("Auto-detected product config: %s -> %s", device_name, file_path)
return _load_config_from_file(file_path)
Expand Down
33 changes: 20 additions & 13 deletions tests/test_connection_cleanup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math
import struct
import sys
import types
from pathlib import Path
Expand Down Expand Up @@ -338,39 +340,44 @@ def test_ethercat_comm_keeps_default_708_tpdo_layout():
assert [region.count for region in comm.config.tactile_regions] == [52, 31, 31, 31, 31]


def test_ethercat_l1_accepts_extended_pdo_sizes_and_packs_per_joint_commands():
def test_ethercat_l1_uses_configured_tactile_pdo_sizes_and_default_rpdo():
config = load_product_config(ProductType.L1)
comm = EthercatComm.__new__(EthercatComm)
comm._client = FakeEthercatClientForSend()
comm.update_config(config)

assert comm._expected_tpdo_sizes == (92, 1302)
assert comm._expected_rpdo_size == 36
assert comm._expected_tpdo_sizes == (1168, 1324)
assert comm._expected_rpdo_size == 38

comm.move_joints(
[JointCommand(id=JointId.FF_MCP, angle=12.3, speed=-4, torque=5)],
CtrlMode.SPEED,
)

data = comm._client.sent[-1]
assert len(data) == 36
assert data[0:6] == bytes.fromhex("02 00 00 00 00 00")
assert data[12:18] == bytes.fromhex("02 00 7b 00 fc 05")
assert len(data) == 38
assert data[0:2] == bytes.fromhex("02 00")
angle, speed, torque = struct.unpack_from("<fbb", data, 14)
assert math.isclose(angle, math.radians(12.3), rel_tol=1e-6)
assert speed == -4
assert torque == 5

comm.stop()
assert comm._client.sent[-1][0:6] == bytes.fromhex("00 01 00 00 00 00")
assert comm._client.sent[-1][0:2] == bytes.fromhex("00 01")


def test_ethercat_l1_extended_tpdo_parses_joint_prefix():
def test_ethercat_l1_tpdo_parses_joint_prefix_with_configured_tactile_size():
config = load_product_config(ProductType.L1)
data = bytearray(1302)
data = bytearray(1324)
offset = 4
for joint_id in config.valid_joints:
if joint_id == JointId.FF_MCP:
data[offset:offset + 6] = bytes.fromhex("01 00 78 00 fc 05")
data[offset:offset + 8] = struct.pack(
"<BBfbb", 1, 0, math.radians(12.0), -4, 5
)
else:
data[offset:offset + 6] = bytes.fromhex("00 00 00 00 00 00")
offset += 6
data[offset:offset + 8] = bytes(8)
offset += 8

comm = EthercatComm.__new__(EthercatComm)
comm._client = FakeEthercatClientForRecv(bytes(data))
Expand All @@ -382,7 +389,7 @@ def test_ethercat_l1_extended_tpdo_parses_joint_prefix():
assert isinstance(ff_mcp, JointData)
assert ff_mcp.state == State.RUNNING
assert ff_mcp.error == ErrorCode.NORMAL
assert ff_mcp.angle == 12.0
assert math.isclose(ff_mcp.angle, 12.0, rel_tol=1e-6)
assert ff_mcp.speed == -4
assert ff_mcp.torque == 5

Expand Down
9 changes: 5 additions & 4 deletions tests/test_modbus_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_l1_profile_loads_protocol_register_map():
config = load_product_config(ProductType.L1)
profile = get_modbus_profile(config)

assert config.name == "L1-Hand-V1"
assert config.name == "GHand Lite 1"
assert config.modbus_profile == "l1"
assert profile.name == "l1"
assert profile.joint_input_addresses[JointId.THUMB_TMC_FE] == 0x1023
Expand All @@ -111,6 +111,8 @@ def test_l1_profile_loads_protocol_register_map():
assert JointId.MF_PIP not in config.joint_limits
assert JointId.RF_PIP not in config.joint_limits
assert JointId.LF_PIP not in config.joint_limits
assert config.has_tactile is True
assert [region.count for region in config.tactile_regions] == [80] * 5


def test_canfd_g5_connection_uses_legacy_timer_register():
Expand Down Expand Up @@ -149,12 +151,11 @@ def test_l1_config_can_be_found_by_device_name():
config = find_config_by_name("L1-Hand-V1")

assert config is not None
assert config.name == "L1-Hand-V1"
assert config.name == "GHand Lite 1"
assert config.modbus_profile == "l1"

alias_config = find_config_by_name("XiaoShun-Hand")
assert alias_config is not None
assert alias_config.name == "L1-Hand-V1"
assert alias_config is None


def test_l1_hand_type_uses_low_byte():
Expand Down