Skip to content

Commit ead4491

Browse files
authored
feat(hardware-testing): stacker estop and door switch qc scripts (#16924)
1 parent 84a57ce commit ead4491

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
test_z_axis,
1111
test_x_axis,
1212
test_l_axis,
13+
test_door_switch,
14+
test_estop,
1315
)
1416

1517

@@ -20,6 +22,8 @@ class TestSection(enum.Enum):
2022
Z_AXIS = "Z_AXIS"
2123
L_AXIS = "L_AXIS"
2224
X_AXIS = "X_AXIS"
25+
DOOR_SWITCH = "DOOR_SWITCH"
26+
ESTOP = "ESTOP"
2327

2428

2529
@dataclass
@@ -47,6 +51,14 @@ class TestConfig:
4751
TestSection.X_AXIS,
4852
test_x_axis.run,
4953
),
54+
(
55+
TestSection.DOOR_SWITCH,
56+
test_door_switch.run,
57+
),
58+
(
59+
TestSection.ESTOP,
60+
test_estop.run,
61+
),
5062
]
5163

5264

@@ -71,5 +83,13 @@ def build_report(test_name: str) -> CSVReport:
7183
title=TestSection.X_AXIS.value,
7284
lines=test_x_axis.build_csv_lines(),
7385
),
86+
CSVSection(
87+
title=TestSection.DOOR_SWITCH.value,
88+
lines=test_door_switch.build_csv_lines(),
89+
),
90+
CSVSection(
91+
title=TestSection.ESTOP.value,
92+
lines=test_estop.build_csv_lines(),
93+
),
7494
],
7595
)

hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/driver.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ def get_hopper_door_closed(self) -> bool:
176176
assert match, f"Incorrect Response for hopper door switch: {res}"
177177
return bool(int(match.group(1)))
178178

179+
def get_estop(self) -> bool:
180+
"""Get E-Stop status.
181+
182+
:return: True if E-Stop is triggered, False otherwise
183+
"""
184+
if self._simulating:
185+
return True
186+
187+
_LS_RE = re.compile(r"^M112 (\d) OK\n")
188+
res = self._send_and_recv("M112\n", "M112 ")
189+
match = _LS_RE.match(res)
190+
assert match, f"Incorrect Response for E-Stop switch: {res}"
191+
return bool(int(match.group(1)))
192+
179193
def move_in_mm(
180194
self, axis: StackerAxis, distance: float, params: MoveParams | None = None
181195
) -> None:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Test Door Switch."""
2+
3+
4+
from typing import List, Union
5+
from hardware_testing.data import ui
6+
from hardware_testing.data.csv_report import (
7+
CSVReport,
8+
CSVLine,
9+
CSVLineRepeating,
10+
CSVResult,
11+
)
12+
13+
from .driver import FlexStacker
14+
15+
16+
def build_csv_lines() -> List[Union[CSVLine, CSVLineRepeating]]:
17+
"""Build CSV Lines."""
18+
return [
19+
CSVLine("close-door", [CSVResult]),
20+
CSVLine("open-door", [CSVResult]),
21+
]
22+
23+
24+
def run(driver: FlexStacker, report: CSVReport, section: str) -> None:
25+
"""Run."""
26+
ui.print_header("Close Door")
27+
if not driver._simulating:
28+
ui.get_user_ready("Close the hopper door")
29+
closed = driver.get_hopper_door_closed()
30+
report(section, "close-door", [CSVResult.from_bool(closed)])
31+
32+
ui.print_header("Open Door")
33+
if not driver._simulating:
34+
ui.get_user_ready("Open the hopper door")
35+
closed = driver.get_hopper_door_closed()
36+
report(section, "open-door", [CSVResult.from_bool(not closed)])
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Test E-Stop."""
2+
3+
4+
from typing import List, Union
5+
from hardware_testing.data import ui
6+
from hardware_testing.data.csv_report import (
7+
CSVReport,
8+
CSVLine,
9+
CSVLineRepeating,
10+
CSVResult,
11+
)
12+
13+
from .driver import FlexStacker, Direction, StackerAxis
14+
15+
16+
def build_csv_lines() -> List[Union[CSVLine, CSVLineRepeating]]:
17+
"""Build CSV Lines."""
18+
return [
19+
CSVLine("trigger-estop", [CSVResult]),
20+
CSVLine("x-move-disabled", [CSVResult]),
21+
CSVLine("z-move-disabled", [CSVResult]),
22+
CSVLine("l-move-disabled", [CSVResult]),
23+
CSVLine("untrigger-estop", [CSVResult]),
24+
]
25+
26+
27+
def axis_at_limit(driver: FlexStacker, axis: StackerAxis) -> Direction:
28+
"""Check which direction an axis is at the limit switch."""
29+
if axis is StackerAxis.L:
30+
# L axis only has one limit switch
31+
if driver.get_limit_switch(axis, Direction.RETRACT):
32+
print(axis, "is at ", Direction.RETRACT, "limit switch")
33+
return Direction.RETRACT
34+
else:
35+
for dir in Direction:
36+
if driver.get_limit_switch(axis, dir):
37+
print(axis, "is at ", dir, "limit switch")
38+
return dir
39+
raise RuntimeError(f"{axis} is not at any limit switch")
40+
41+
42+
def run(driver: FlexStacker, report: CSVReport, section: str) -> None:
43+
"""Run."""
44+
if not driver._simulating and driver.get_estop():
45+
raise RuntimeError("E-Stop is either triggered/not attached.")
46+
47+
x_limit = axis_at_limit(driver, StackerAxis.X)
48+
z_limit = axis_at_limit(driver, StackerAxis.Z)
49+
l_limit = axis_at_limit(driver, StackerAxis.L)
50+
51+
ui.print_header("Trigger E-Stop")
52+
if not driver._simulating:
53+
ui.get_user_ready("Trigger the E-Stop")
54+
55+
if not driver.get_estop():
56+
print("E-Stop is not triggered")
57+
report(section, "trigger-estop", [CSVResult.FAIL])
58+
return
59+
60+
report(section, "trigger-estop", [CSVResult.PASS])
61+
62+
print("try to move X axis...")
63+
driver.move_in_mm(StackerAxis.X, x_limit.opposite().distance(10))
64+
print("X should not move")
65+
report(
66+
section,
67+
"x-move-disabled",
68+
[CSVResult.from_bool(driver.get_limit_switch(StackerAxis.X, x_limit))],
69+
)
70+
71+
print("try to move Z axis...")
72+
driver.move_in_mm(StackerAxis.Z, z_limit.opposite().distance(10))
73+
print("Z should not move")
74+
report(
75+
section,
76+
"z-move-disabled",
77+
[CSVResult.from_bool(driver.get_limit_switch(StackerAxis.Z, z_limit))],
78+
)
79+
80+
print("try to move L axis...")
81+
driver.move_in_mm(StackerAxis.L, l_limit.opposite().distance(10))
82+
print("L should not move")
83+
report(
84+
section,
85+
"l-move-disabled",
86+
[CSVResult.from_bool(driver.get_limit_switch(StackerAxis.L, l_limit))],
87+
)
88+
89+
if not driver._simulating:
90+
ui.get_user_ready("Untrigger the E-Stop")
91+
report(section, "untrigger-estop", [CSVResult.from_bool(not driver.get_estop())])

0 commit comments

Comments
 (0)