Skip to content

Commit bbfccf2

Browse files
authored
feat(api): Expose the GET_ESTOP_ENGAGED (M112) G-Code for the Flex Stacker to support testing. (#19135)
1 parent 5408ea2 commit bbfccf2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

api/src/opentrons/drivers/flex_stacker/driver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ def parse_installation_detected(cls, response: str) -> bool:
128128
)
129129
return bool(int(match.group(1)))
130130

131+
@classmethod
132+
def parse_estop_engaged(cls, response: str) -> bool:
133+
"""Parse estop enagaged."""
134+
_RE = re.compile(rf"^{GCODE.GET_ESTOP_ENGAGED} E:(\d)$")
135+
match = _RE.match(response)
136+
if not match:
137+
raise ValueError(f"Incorrect Response for Estop engaged: {response}")
138+
return bool(int(match.group(1)))
139+
131140
@classmethod
132141
def parse_move_params(cls, response: str) -> MoveParams:
133142
"""Parse move params."""
@@ -652,6 +661,16 @@ async def get_installation_detected(self) -> bool:
652661
)
653662
return self.parse_installation_detected(response)
654663

664+
async def get_estop_engaged(self) -> bool:
665+
"""Get whether or not the estop was detected by this stacker.
666+
667+
:return: True if the estop is trigguered, False otherwise
668+
"""
669+
response = await self._connection.send_command(
670+
GCODE.GET_ESTOP_ENGAGED.build_command()
671+
)
672+
return self.parse_estop_engaged(response)
673+
655674
async def move_in_mm(
656675
self, axis: StackerAxis, distance: float, params: MoveParams | None = None
657676
) -> MoveResult:

api/src/opentrons/drivers/flex_stacker/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GCODE(str, Enum):
1212
HOME_AXIS = "G28"
1313
STOP_MOTORS = "M0"
1414
ENABLE_MOTORS = "M17"
15+
GET_ESTOP_ENGAGED = "M112"
1516
GET_RESET_REASON = "M114"
1617
DEVICE_INFO = "M115"
1718
GET_LIMIT_SWITCH = "M119"

api/tests/opentrons/drivers/flex_stacker/test_driver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,29 @@ async def test_set_tof_configuration(
750750
)
751751
connection.send_command.assert_any_call(set_config)
752752
connection.reset_mock()
753+
754+
755+
async def test_get_estop_engaged(
756+
subject: FlexStackerDriver, connection: AsyncMock
757+
) -> None:
758+
"""It should send a get estop command return boolean."""
759+
connection.send_command.return_value = "M112 E:1"
760+
response = await subject.get_estop_engaged()
761+
assert response
762+
763+
estop = types.GCODE.GET_ESTOP_ENGAGED.build_command()
764+
connection.send_command.assert_any_call(estop)
765+
connection.reset_mock()
766+
767+
768+
async def test_get_install_detected(
769+
subject: FlexStackerDriver, connection: AsyncMock
770+
) -> None:
771+
"""It should send a get install detected command and return boolean."""
772+
connection.send_command.return_value = "M123 I:1"
773+
response = await subject.get_installation_detected()
774+
assert response
775+
776+
install_detect = types.GCODE.GET_INSTALL_DETECTED.build_command()
777+
connection.send_command.assert_any_call(install_detect)
778+
connection.reset_mock()

0 commit comments

Comments
 (0)