From 2b4e6575460591d93c0c399b98454cfee3b6bd95 Mon Sep 17 00:00:00 2001 From: Brayan Almonte Date: Wed, 27 Nov 2024 16:22:57 -0500 Subject: [PATCH] fix(hardware-testing): add __init__.py to modules/ so it gets packed in the build + other Flex stacker QC fixes. (#16995) - add an `__init__.py` so it does, this will make it so we can push to the robot. - change the way we validate no movement when in e-stop - don't wait for ack from stop_motor `M0` command. --- .../hardware_testing/modules/__init__.py | 1 + .../modules/flex_stacker_evt_qc/driver.py | 9 +++- .../modules/flex_stacker_evt_qc/test_estop.py | 50 +++++++++++++------ 3 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 hardware-testing/hardware_testing/modules/__init__.py diff --git a/hardware-testing/hardware_testing/modules/__init__.py b/hardware-testing/hardware_testing/modules/__init__.py new file mode 100644 index 00000000000..abbbb3c6ffc --- /dev/null +++ b/hardware-testing/hardware_testing/modules/__init__.py @@ -0,0 +1 @@ +"""Module QC Scripts.""" diff --git a/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/driver.py b/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/driver.py index 791ba5ed566..afa24d1f315 100644 --- a/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/driver.py +++ b/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/driver.py @@ -119,10 +119,15 @@ def __init__(self, port: str, simulating: bool = False) -> None: if not self._simulating: self._serial = serial.Serial(port, baudrate=STACKER_FREQ, timeout=60) - def _send_and_recv(self, msg: str, guard_ret: str = "") -> str: + def _send_and_recv( + self, msg: str, guard_ret: str = "", response_required: bool = True + ) -> str: """Internal utility to send a command and receive the response.""" assert not self._simulating + self._serial.reset_input_buffer() self._serial.write(msg.encode()) + if not response_required: + return "OK\n" ret = self._serial.readline() if guard_ret: if not ret.startswith(guard_ret.encode()): @@ -159,7 +164,7 @@ def stop_motor(self) -> None: """Stop motor movement.""" if self._simulating: return - self._send_and_recv("M0\n") + self._send_and_recv("M0\n", response_required=False) def get_limit_switch(self, axis: StackerAxis, direction: Direction) -> bool: """Get limit switch status. diff --git a/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/test_estop.py b/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/test_estop.py index 2a2f24161b7..31df6f1decc 100644 --- a/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/test_estop.py +++ b/hardware-testing/hardware_testing/modules/flex_stacker_evt_qc/test_estop.py @@ -56,14 +56,23 @@ def run(driver: FlexStacker, report: CSVReport, section: str) -> None: report(section, "trigger-estop", [CSVResult.PASS]) - print("try to move X axis...") - driver.move_in_mm(StackerAxis.X, x_limit.opposite().distance(10)) - print("X should not move") - report( - section, - "x-move-disabled", - [CSVResult.from_bool(driver.get_limit_switch(StackerAxis.X, x_limit))], - ) + print("Check X limit switch...") + limit_switch_triggered = driver.get_limit_switch(StackerAxis.X, x_limit) + if limit_switch_triggered: + report( + section, + "x-move-disabled", + [CSVResult.from_bool(False)], + ) + else: + print("try to move X axis back to the limit switch...") + driver.move_in_mm(StackerAxis.X, x_limit.distance(3)) + print("X should not move") + report( + section, + "x-move-disabled", + [CSVResult.from_bool(not driver.get_limit_switch(StackerAxis.X, x_limit))], + ) print("try to move Z axis...") driver.move_in_mm(StackerAxis.Z, z_limit.opposite().distance(10)) @@ -74,14 +83,23 @@ def run(driver: FlexStacker, report: CSVReport, section: str) -> None: [CSVResult.from_bool(driver.get_limit_switch(StackerAxis.Z, z_limit))], ) - print("try to move L axis...") - driver.move_in_mm(StackerAxis.L, l_limit.opposite().distance(10)) - print("L should not move") - report( - section, - "l-move-disabled", - [CSVResult.from_bool(driver.get_limit_switch(StackerAxis.L, l_limit))], - ) + print("Check L limit switch...") + limit_switch_triggered = driver.get_limit_switch(StackerAxis.L, l_limit) + if limit_switch_triggered: + report( + section, + "l-move-disabled", + [CSVResult.from_bool(False)], + ) + else: + print("try to move L axis back to the limit switch...") + driver.move_in_mm(StackerAxis.L, l_limit.distance(1)) + print("L should not move") + report( + section, + "l-move-disabled", + [CSVResult.from_bool(not driver.get_limit_switch(StackerAxis.L, l_limit))], + ) if not driver._simulating: ui.get_user_ready("Untrigger the E-Stop")