Skip to content

Commit

Permalink
add set_led_state api
Browse files Browse the repository at this point in the history
reset led state after stall
  • Loading branch information
vegano1 committed Jan 23, 2025
1 parent c4bad1a commit 9e9d475
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/src/opentrons/drivers/flex_stacker/abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Protocol
from typing import List, Optional, Protocol

from .types import (
LEDPattern,
LimitSwitchStatus,
MoveResult,
StackerAxis,
Expand Down Expand Up @@ -122,9 +123,15 @@ async def home_axis(self, axis: StackerAxis, direction: Direction) -> MoveResult
...

async def set_led(
self, power: float, color: LEDColor | None = None, external: bool | None = None
self,
power: float,
color: Optional[LEDColor] = None,
external: Optional[bool] = None,
pattern: Optional[LEDPattern] = None,
duration: Optional[int] = None,
reps: Optional[int] = None,
) -> bool:
"""Set LED color of status bar."""
"""Set LED Status bar color and pattern."""
...

async def enter_programming_mode(self) -> None:
Expand Down
31 changes: 31 additions & 0 deletions api/src/opentrons/hardware_control/modules/flex_stacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from opentrons.drivers.flex_stacker.types import (
Direction,
LEDColor,
LEDPattern,
MoveParams,
MoveResult,
StackerAxis,
Expand Down Expand Up @@ -114,6 +116,11 @@ async def build(
disconnected_callback=disconnected_callback,
)

# Enable stallguard
await driver.set_stallguard_threshold(StackerAxis.X, True, 2)
await driver.set_stallguard_threshold(StackerAxis.Z, True, 2)
await driver.set_stallguard_threshold(StackerAxis.L, True, 2)

try:
await poller.start()
except Exception:
Expand Down Expand Up @@ -145,6 +152,7 @@ def __init__(
self._reader = reader
self._poller = poller
self._stacker_status = FlexStackerStatus.IDLE
self._stall_detected = False;

async def cleanup(self) -> None:
"""Stop the poller task"""
Expand Down Expand Up @@ -227,6 +235,25 @@ def bootloader(self) -> UploadFunction:
async def deactivate(self, must_be_running: bool = True) -> None:
await self._driver.stop_motors()

async def reset_stall_detected(self) -> None:
"""Sets the statusbar to normal."""
if self._stall_detected:
await self.set_led_state(0.5, LEDColor.GREEN, LEDPattern.STATIC)
self._stall_detected = False

async def set_led_state(
self,
power: float,
color: Optional[LEDColor] = None,
pattern: Optional[LEDPattern] = None,
duration: Optional[int] = None,
reps: Optional[int] = None,
) -> bool:
"""Sets the statusbar state."""
return await self._driver.set_led(
power, color=color, pattern=pattern, duration=duration, reps=reps
)

async def move_axis(
self,
axis: StackerAxis,
Expand All @@ -237,6 +264,7 @@ async def move_axis(
current: Optional[float] = None,
) -> bool:
"""Move the axis in a direction by the given distance in mm."""
await self.reset_stall_detected()
motion_params = STACKER_MOTION_CONFIG[axis]["move"]
await self._driver.set_run_current(axis, current or motion_params.current or 0)
if any([speed, acceleration]):
Expand All @@ -245,6 +273,7 @@ async def move_axis(
distance = direction.distance(distance)
res = await self._driver.move_in_mm(axis, distance, params=motion_params)
if res == MoveResult.STALL_ERROR:
self._stall_detected = True
raise FlexStackerStallError(self.device_info["serial"], axis)
return res == MoveResult.NO_ERROR

Expand All @@ -256,6 +285,7 @@ async def home_axis(
acceleration: Optional[float] = None,
current: Optional[float] = None,
) -> bool:
await self.reset_stall_detected()
motion_params = STACKER_MOTION_CONFIG[axis]["home"]
await self._driver.set_run_current(axis, current or motion_params.current or 0)
# Set the max hold current for the Z axis
Expand All @@ -268,6 +298,7 @@ async def home_axis(
axis=axis, direction=direction, params=motion_params
)
if success == MoveResult.STALL_ERROR:
self._stall_detected = True
raise FlexStackerStallError(self.device_info["serial"], axis)
return success == MoveResult.NO_ERROR

Expand Down

0 comments on commit 9e9d475

Please sign in to comment.