Skip to content

Commit

Permalink
Added a FlexInstrumentConfigurer for flex-specific configuration ex…
Browse files Browse the repository at this point in the history
…tensions
  • Loading branch information
fsinapi committed Dec 5, 2023
1 parent 1ac290e commit ede3171
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
8 changes: 5 additions & 3 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ def reset_instrument(
self._pipette_handler.reset_instrument(checked_mount)

def get_instrument_offset(
self, mount: OT3Mount
self, mount: Union[top_types.Mount, OT3Mount]
) -> Union[GripperCalibrationOffset, PipetteOffsetSummary, None]:
"""Get instrument calibration data."""
# TODO (spp, 2023-04-19): We haven't introduced a 'calibration_offset' key in
Expand All @@ -2271,11 +2271,13 @@ def get_instrument_offset(
# to be a part of the dict, this getter can be updated to fetch pipette offset
# from the dict, or just remove this getter entirely.

if mount == OT3Mount.GRIPPER:
ot3_mount = OT3Mount.from_mount(mount)

if ot3_mount == OT3Mount.GRIPPER:
gripper_dict = self._gripper_handler.get_gripper_dict()
return gripper_dict["calibration_offset"] if gripper_dict else None
else:
return self._pipette_handler.get_instrument_offset(mount=mount)
return self._pipette_handler.get_instrument_offset(mount=ot3_mount)

async def reset_instrument_offset(
self, mount: Union[top_types.Mount, OT3Mount], to_default: bool = True
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/hardware_control/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .identifiable import Identifiable
from .gripper_controller import GripperController
from .flex_calibratable import FlexCalibratable
from .flex_instrument_configurer import FlexInstrumentConfigurer

from .types import CalibrationType, MountArgType, ConfigType

Expand Down Expand Up @@ -54,6 +55,7 @@ class FlexHardwareControlInterface(
HardwareControlInterface[CalibrationType, MountArgType, ConfigType],
GripperController,
FlexCalibratable,
FlexInstrumentConfigurer[MountArgType],
Protocol[CalibrationType, MountArgType, ConfigType],
):
"""A mypy protocol for a hardware controller with Flex-specific extensions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Flex-specific extensions to instrument configuration."""
from typing import Union
from typing_extensions import Protocol

from .types import MountArgType

from opentrons.hardware_control.dev_types import (
PipetteStateDict,
)
from opentrons.hardware_control.instruments.ot3.instrument_calibration import (
PipetteOffsetSummary,
GripperCalibrationOffset,
)


class FlexInstrumentConfigurer(Protocol[MountArgType]):
"""A protocol specifying Flex-specific extensions to instrument configuration."""

async def get_instrument_state(
self,
mount: MountArgType,
) -> PipetteStateDict:
...

def get_instrument_offset(
self, mount: MountArgType
) -> Union[GripperCalibrationOffset, PipetteOffsetSummary, None]:
...
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Optional
from typing_extensions import Protocol

from opentrons.hardware_control.dev_types import GripperDict


class GripperController(Protocol):
"""A protocol specifying gripper API functions."""
Expand Down Expand Up @@ -29,3 +31,8 @@ def gripper_jaw_can_home(self) -> bool:
currently holding something.
"""
...

@property
def attached_gripper(self) -> Optional[GripperDict]:
"""Get a dict of all attached grippers."""
...
10 changes: 5 additions & 5 deletions robot-server/robot_server/instruments/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from robot_server.subsystems.router import status_route_for, update_route_for

if TYPE_CHECKING:
from opentrons.hardware_control.ot3api import OT3API
from opentrons.hardware_control import OT3HardwareControlAPI

instruments_router = APIRouter()

Expand Down Expand Up @@ -151,7 +151,7 @@ def _bad_pipette_response(subsystem: SubSystem) -> BadPipette:


async def _get_gripper_instrument_data(
hardware: "OT3API",
hardware: "OT3HardwareControlAPI",
attached_gripper: Optional[GripperDict],
) -> Optional[AttachedItem]:
subsys = HWSubSystem.of_mount(OT3Mount.GRIPPER)
Expand All @@ -167,7 +167,7 @@ async def _get_gripper_instrument_data(


async def _get_pipette_instrument_data(
hardware: "OT3API",
hardware: "OT3HardwareControlAPI",
attached_pipettes: Dict[Mount, PipetteDict],
mount: Mount,
) -> Optional[AttachedItem]:
Expand All @@ -193,7 +193,7 @@ async def _get_pipette_instrument_data(


async def _get_instrument_data(
hardware: "OT3API",
hardware: "OT3HardwareControlAPI",
) -> List[AttachedItem]:
attached_pipettes = hardware.attached_pipettes
attached_gripper = hardware.attached_gripper
Expand All @@ -214,7 +214,7 @@ async def _get_instrument_data(


async def _get_attached_instruments_ot3(
hardware: "OT3API",
hardware: "OT3HardwareControlAPI",
) -> PydanticResponse[SimpleMultiBody[AttachedItem]]:
# OT3
await hardware.cache_instruments()
Expand Down

0 comments on commit ede3171

Please sign in to comment.