Skip to content

Commit

Permalink
Rework Protocol Engine's TipHandler.add_tip() into TipHandler.cache_t…
Browse files Browse the repository at this point in the history
…ip().
  • Loading branch information
SyntaxColoring committed Oct 23, 2024
1 parent b8c3f9e commit 1bfc529
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ async def _drop_tip(self) -> None:
try:
if self._state_store.labware.get_fixed_trash_id() == FIXED_TRASH_ID:
# OT-2 and Flex 2.15 protocols will default to the Fixed Trash Labware
await self._tip_handler.add_tip(pipette_id=pipette_id, tip=tip)
await self._tip_handler.cache_tip(
pipette_id=pipette_id, tip=tip
)
await self._movement_handler.move_to_well(
pipette_id=pipette_id,
labware_id=FIXED_TRASH_ID,
Expand All @@ -90,7 +92,9 @@ async def _drop_tip(self) -> None:
)
elif self._state_store.config.robot_type == "OT-2 Standard":
# API 2.16 and above OT2 protocols use addressable areas
await self._tip_handler.add_tip(pipette_id=pipette_id, tip=tip)
await self._tip_handler.cache_tip(
pipette_id=pipette_id, tip=tip
)
await self._movement_handler.move_to_addressable_area(
pipette_id=pipette_id,
addressable_area_name="fixedTrash",
Expand Down
34 changes: 13 additions & 21 deletions api/src/opentrons/protocol_engine/execution/tip_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def drop_tip(self, pipette_id: str, home_after: Optional[bool]) -> None:
TipAttachedError
"""

async def add_tip(self, pipette_id: str, tip: TipGeometry) -> None:
async def cache_tip(self, pipette_id: str, tip: TipGeometry) -> None:
"""Tell the Hardware API that a tip is attached."""

async def get_tip_presence(self, pipette_id: str) -> TipPresenceStatus:
Expand Down Expand Up @@ -234,31 +234,23 @@ async def pick_up_tip(
labware_definition=self._state_view.labware.get_definition(labware_id),
nominal_fallback=nominal_tip_geometry.length,
)
tip_geometry = TipGeometry(
length=actual_tip_length,
diameter=nominal_tip_geometry.diameter,
volume=nominal_tip_geometry.volume,
)

await self._hardware_api.tip_pickup_moves(
mount=hw_mount, presses=None, increment=None
)
# Allow TipNotAttachedError to propagate.
await self.verify_tip_presence(pipette_id, TipPresenceStatus.PRESENT)

self._hardware_api.cache_tip(hw_mount, actual_tip_length)
await self._hardware_api.prepare_for_aspirate(hw_mount)

self._hardware_api.set_current_tiprack_diameter(
mount=hw_mount,
tiprack_diameter=nominal_tip_geometry.diameter,
)
await self.cache_tip(pipette_id, tip_geometry)

self._hardware_api.set_working_volume(
mount=hw_mount,
tip_volume=nominal_tip_geometry.volume,
)
await self._hardware_api.prepare_for_aspirate(hw_mount)

return TipGeometry(
length=actual_tip_length,
diameter=nominal_tip_geometry.diameter,
volume=nominal_tip_geometry.volume,
)
return tip_geometry

async def drop_tip(self, pipette_id: str, home_after: Optional[bool]) -> None:
"""See documentation on abstract base class."""
Expand All @@ -279,11 +271,11 @@ async def drop_tip(self, pipette_id: str, home_after: Optional[bool]) -> None:
self._hardware_api.remove_tip(hw_mount)
self._hardware_api.set_current_tiprack_diameter(hw_mount, 0)

async def add_tip(self, pipette_id: str, tip: TipGeometry) -> None:
async def cache_tip(self, pipette_id: str, tip: TipGeometry) -> None:
"""See documentation on abstract base class."""
hw_mount = self._state_view.pipettes.get_mount(pipette_id).to_hw_mount()

self._hardware_api.add_tip(mount=hw_mount, tip_length=tip.length)
self._hardware_api.cache_tip(mount=hw_mount, tip_length=tip.length)

self._hardware_api.set_current_tiprack_diameter(
mount=hw_mount,
Expand Down Expand Up @@ -422,12 +414,12 @@ async def drop_tip(
expected_has_tip=True,
)

async def add_tip(self, pipette_id: str, tip: TipGeometry) -> None:
async def cache_tip(self, pipette_id: str, tip: TipGeometry) -> None:
"""Add a tip using a virtual pipette.
This should not be called when using virtual pipettes.
"""
assert False, "TipHandler.add_tip should not be used with virtual pipettes"
assert False, "TipHandler.cache_tip should not be used with virtual pipettes"

async def verify_tip_presence(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def test_hardware_stopping_sequence_no_tip_drop(
decoy.verify(await hardware_api.stop(home_after=False), times=1)

decoy.verify(
await mock_tip_handler.add_tip(
await mock_tip_handler.cache_tip(
pipette_id="pipette-id",
tip=TipGeometry(length=1.0, volume=2.0, diameter=3.0),
),
Expand All @@ -181,7 +181,7 @@ async def test_hardware_stopping_sequence_no_pipette(
)

decoy.when(
await mock_tip_handler.add_tip(
await mock_tip_handler.cache_tip(
pipette_id="pipette-id",
tip=TipGeometry(length=1.0, volume=2.0, diameter=3.0),
),
Expand Down Expand Up @@ -271,7 +271,7 @@ async def test_hardware_stopping_sequence_with_fixed_trash(
await movement.home(
axes=[MotorAxis.X, MotorAxis.Y, MotorAxis.LEFT_Z, MotorAxis.RIGHT_Z]
),
await mock_tip_handler.add_tip(
await mock_tip_handler.cache_tip(
pipette_id="pipette-id",
tip=TipGeometry(length=1.0, volume=2.0, diameter=3.0),
),
Expand Down Expand Up @@ -320,7 +320,7 @@ async def test_hardware_stopping_sequence_with_OT2_addressable_area(
await movement.home(
axes=[MotorAxis.X, MotorAxis.Y, MotorAxis.LEFT_Z, MotorAxis.RIGHT_Z]
),
await mock_tip_handler.add_tip(
await mock_tip_handler.cache_tip(
pipette_id="pipette-id",
tip=TipGeometry(length=1.0, volume=2.0, diameter=3.0),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ async def test_add_tip(
MountType.LEFT
)

await subject.add_tip(pipette_id="pipette-id", tip=tip)
await subject.cache_tip(pipette_id="pipette-id", tip=tip)

decoy.verify(
mock_hardware_api.add_tip(mount=Mount.LEFT, tip_length=50),
mock_hardware_api.cache_tip(mount=Mount.LEFT, tip_length=50),
mock_hardware_api.set_current_tiprack_diameter(
mount=Mount.LEFT,
tiprack_diameter=5,
Expand Down

0 comments on commit 1bfc529

Please sign in to comment.