2026-10-21 15:19:07 +09:00
|
|
|
"""Self-check of robot/gripper.py's finger gap from AI_1 (no robot): python tests/test_gripper.py"""
|
2026-10-27 20:22:32 +09:00
|
|
|
import no_robot # noqa: F401 any connection to the robot fails the test
|
2026-10-21 15:19:07 +09:00
|
|
|
from robot import gripper as g
|
|
|
|
|
|
2026-10-29 15:55:03 +09:00
|
|
|
assert g.gap_mm(g.AI_OPEN) == 102.0 and g.gap_mm(g.AI_SHUT) == 77.0 # belly, open / closed (owner)
|
|
|
|
|
assert g.gap_mm(50) == 102.0 and g.gap_mm(5000) == 77.0 # readings past the ends are clamped
|
|
|
|
|
assert abs(g.gap_mm((g.AI_OPEN + g.AI_SHUT) / 2) - 89.5) < 0.01 # linear between
|
|
|
|
|
assert g.gap_mm(g.AI_SHUT, "tips") == 73.0 and g.gap_mm(g.AI_OPEN, "shank") == 66.0
|
2026-10-21 15:19:07 +09:00
|
|
|
assert all(hasattr(g, n) for n in ("MOVE_S", "SENSOR_DI", "READ_TRIES", "READ_GAP_S", "CLOSED_AI", "EMPTY_AI"))
|
2026-11-10 10:11:44 +09:00
|
|
|
|
|
|
|
|
reply = {"tio_ain": [486.0, 486.0], "tio_din": [0, 0], "tio_dout": [0, 1]} # AI_1 floating with no gripper on
|
|
|
|
|
g.arm.cmd = lambda *a, **k: reply
|
|
|
|
|
for fitted, holding in ((True, True), (False, False)):
|
|
|
|
|
g.FITTED = fitted
|
|
|
|
|
s = g.state()
|
|
|
|
|
assert s["holding"] is holding and s["closed"] is holding and s["ai"] == reply["tio_ain"], (fitted, s)
|
2026-10-21 15:19:07 +09:00
|
|
|
print("gripper ok")
|