Skip to content

Commit 9b9ed16

Browse files
authored
fix(hardware-testing): flex-stacker QC script improvements (#16961)
1 parent d5b7e61 commit 9b9ed16

File tree

5 files changed

+77
-32
lines changed

5 files changed

+77
-32
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from hardware_testing.data.csv_report import CSVReport
1515

1616
from .config import TestSection, TestConfig, build_report, TESTS
17-
from .driver import FlexStacker
17+
from .driver import FlexStacker, PlatformStatus
1818

1919

2020
def build_stacker_report(is_simulating: bool) -> Tuple[CSVReport, FlexStacker]:
@@ -42,6 +42,28 @@ async def _main(cfg: TestConfig) -> None:
4242
# BUILD REPORT
4343
report, stacker = build_stacker_report(cfg.simulate)
4444

45+
if not cfg.simulate:
46+
# Perform initial checks before starting tests
47+
# 1. estop should not be pressed
48+
# 2. platform should be removed
49+
if stacker.get_estop():
50+
ui.print_error("ESTOP is pressed, please release it before starting")
51+
ui.get_user_ready("Release ESTOP")
52+
if stacker.get_estop():
53+
ui.print_error("ESTOP is still pressed, cannot start tests")
54+
return
55+
56+
platform_state = stacker.get_platform_status()
57+
if platform_state is PlatformStatus.ERROR:
58+
ui.print_error("Platform sensors are not working properly, aborting")
59+
return
60+
if platform_state is not PlatformStatus.REMOVED:
61+
ui.print_error("Platform must be removed from the carrier before starting")
62+
ui.get_user_ready("Remove platform from {platform_state.value}")
63+
if stacker.get_platform_status() is not PlatformStatus.REMOVED:
64+
ui.print_error("Platform is still detected, cannot start tests")
65+
return
66+
4567
# RUN TESTS
4668
for section, test_run in cfg.tests.items():
4769
ui.print_title(section.value)

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ class TestConfig:
4343
TestSection.Z_AXIS,
4444
test_z_axis.run,
4545
),
46-
(
47-
TestSection.L_AXIS,
48-
test_l_axis.run,
49-
),
5046
(
5147
TestSection.X_AXIS,
5248
test_x_axis.run,
5349
),
5450
(
55-
TestSection.DOOR_SWITCH,
56-
test_door_switch.run,
51+
TestSection.L_AXIS,
52+
test_l_axis.run,
5753
),
5854
(
5955
TestSection.ESTOP,
6056
test_estop.run,
6157
),
58+
(
59+
TestSection.DOOR_SWITCH,
60+
test_door_switch.run,
61+
),
6262
]
6363

6464

@@ -75,21 +75,21 @@ def build_report(test_name: str) -> CSVReport:
7575
title=TestSection.Z_AXIS.value,
7676
lines=test_z_axis.build_csv_lines(),
7777
),
78-
CSVSection(
79-
title=TestSection.L_AXIS.value,
80-
lines=test_l_axis.build_csv_lines(),
81-
),
8278
CSVSection(
8379
title=TestSection.X_AXIS.value,
8480
lines=test_x_axis.build_csv_lines(),
8581
),
8682
CSVSection(
87-
title=TestSection.DOOR_SWITCH.value,
88-
lines=test_door_switch.build_csv_lines(),
83+
title=TestSection.L_AXIS.value,
84+
lines=test_l_axis.build_csv_lines(),
8985
),
9086
CSVSection(
9187
title=TestSection.ESTOP.value,
9288
lines=test_estop.build_csv_lines(),
9389
),
90+
CSVSection(
91+
title=TestSection.DOOR_SWITCH.value,
92+
lines=test_door_switch.build_csv_lines(),
93+
),
9494
],
9595
)

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""FLEX Stacker Driver."""
2+
from typing import Tuple
23
from dataclasses import dataclass
34
import serial # type: ignore[import]
45
from serial.tools.list_ports import comports # type: ignore[import]
@@ -38,6 +39,26 @@ def __str__(self) -> str:
3839
return self.name
3940

4041

42+
class PlatformStatus(Enum):
43+
"""Platform Status."""
44+
45+
REMOVED = 0
46+
EXTENTED = 1
47+
RETRACTED = 2
48+
ERROR = 4
49+
50+
@classmethod
51+
def from_tuple(cls, status: Tuple[int, int]) -> "PlatformStatus":
52+
"""Get platform status from tuple."""
53+
if status == (0, 0):
54+
return PlatformStatus.REMOVED
55+
if status == (1, 0):
56+
return PlatformStatus.EXTENTED
57+
if status == (0, 1):
58+
return PlatformStatus.RETRACTED
59+
return PlatformStatus.ERROR
60+
61+
4162
class Direction(Enum):
4263
"""Direction."""
4364

@@ -67,9 +88,9 @@ class MoveParams:
6788

6889
def __str__(self) -> str:
6990
"""Convert to string."""
70-
v = "V:" + str(self.max_speed) if self.max_speed else ""
71-
a = "A:" + str(self.acceleration) if self.acceleration else ""
72-
d = "D:" + str(self.max_speed_discont) if self.max_speed_discont else ""
91+
v = "V" + str(self.max_speed) if self.max_speed else ""
92+
a = "A" + str(self.acceleration) if self.acceleration else ""
93+
d = "D" + str(self.max_speed_discont) if self.max_speed_discont else ""
7394
return f"{v} {a} {d}".strip()
7495

7596

@@ -100,7 +121,7 @@ def __init__(self, port: str, simulating: bool = False) -> None:
100121

101122
def _send_and_recv(self, msg: str, guard_ret: str = "") -> str:
102123
"""Internal utility to send a command and receive the response."""
103-
assert self._simulating
124+
assert not self._simulating
104125
self._serial.write(msg.encode())
105126
ret = self._serial.readline()
106127
if guard_ret:
@@ -142,7 +163,7 @@ def get_limit_switch(self, axis: StackerAxis, direction: Direction) -> bool:
142163
if self._simulating:
143164
return True
144165

145-
_LS_RE = re.compile(rf"^M119 .*{axis.name}{direction.name[0]}:(\d) .* OK\n")
166+
_LS_RE = re.compile(rf"^M119 .*{axis.name}{direction.name[0]}:(\d).* OK\n")
146167
res = self._send_and_recv("M119\n", "M119 XE:")
147168
match = _LS_RE.match(res)
148169
assert match, f"Incorrect Response for limit switch: {res}"
@@ -156,12 +177,23 @@ def get_platform_sensor(self, direction: Direction) -> bool:
156177
if self._simulating:
157178
return True
158179

159-
_LS_RE = re.compile(rf"^M121 .*{direction.name[0]}:(\d) .* OK\n")
160-
res = self._send_and_recv("M121\n", "M119 E:")
180+
_LS_RE = re.compile(rf"^M121 .*{direction.name[0]}:(\d).* OK\n")
181+
res = self._send_and_recv("M121\n", "M121 E:")
161182
match = _LS_RE.match(res)
162183
assert match, f"Incorrect Response for platform sensor: {res}"
163184
return bool(int(match.group(1)))
164185

186+
def get_platform_status(self) -> PlatformStatus:
187+
"""Get platform status."""
188+
if self._simulating:
189+
return PlatformStatus.REMOVED
190+
191+
_LS_RE = re.compile(r"^M121 E:(\d) R:(\d) OK\n")
192+
res = self._send_and_recv("M121\n", "M121 ")
193+
match = _LS_RE.match(res)
194+
assert match, f"Incorrect Response for platform status: {res}"
195+
return PlatformStatus.from_tuple((int(match.group(1)), int(match.group(2))))
196+
165197
def get_hopper_door_closed(self) -> bool:
166198
"""Get whether or not door is closed.
167199
@@ -205,7 +237,7 @@ def move_to_limit_switch(
205237
if self._simulating:
206238
return
207239
self._send_and_recv(
208-
f"G5 {axis.name}{direction.value} {params or ''}\n", "G0 OK"
240+
f"G5 {axis.name}{direction.value} {params or ''}\n", "G5 OK"
209241
)
210242

211243
def __del__(self) -> None:

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ def axis_at_limit(driver: FlexStacker, axis: StackerAxis) -> Direction:
4141

4242
def run(driver: FlexStacker, report: CSVReport, section: str) -> None:
4343
"""Run."""
44-
if not driver._simulating and driver.get_estop():
45-
raise RuntimeError("E-Stop is either triggered/not attached.")
46-
4744
x_limit = axis_at_limit(driver, StackerAxis.X)
4845
z_limit = axis_at_limit(driver, StackerAxis.Z)
4946
l_limit = axis_at_limit(driver, StackerAxis.L)

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
from .driver import FlexStacker, StackerAxis, Direction
1212

1313

14-
class LimitSwitchError(Exception):
15-
"""Limit Switch Error."""
16-
17-
pass
18-
19-
2014
def build_csv_lines() -> List[Union[CSVLine, CSVLineRepeating]]:
2115
"""Build CSV Lines."""
2216
return [
@@ -35,12 +29,12 @@ def get_latch_held_switch(driver: FlexStacker) -> bool:
3529

3630
def close_latch(driver: FlexStacker) -> None:
3731
"""Close latch."""
38-
driver.move_to_limit_switch(StackerAxis.L, Direction.EXTENT)
32+
driver.move_to_limit_switch(StackerAxis.L, Direction.RETRACT)
3933

4034

4135
def open_latch(driver: FlexStacker) -> None:
4236
"""Open latch."""
43-
driver.move_in_mm(StackerAxis.L, -22)
37+
driver.move_in_mm(StackerAxis.L, 22)
4438

4539

4640
def run(driver: FlexStacker, report: CSVReport, section: str) -> None:

0 commit comments

Comments
 (0)