Skip to content

Commit

Permalink
fix(protocol-engine): Update location after liquidProbe and `tryLiq…
Browse files Browse the repository at this point in the history
…uidProbe` (#15867)
  • Loading branch information
SyntaxColoring authored Aug 2, 2024
1 parent c66e43e commit a2b5c44
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 76 deletions.
154 changes: 78 additions & 76 deletions api/src/opentrons/protocol_engine/state/pipettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
NozzleMap,
)
from opentrons.protocol_engine.actions.actions import FailCommandAction
from opentrons.protocol_engine.commands.aspirate import Aspirate
from opentrons.protocol_engine.commands.dispense import Dispense
from opentrons.protocol_engine.commands.aspirate_in_place import AspirateInPlace
from opentrons.protocol_engine.commands.dispense_in_place import DispenseInPlace
from opentrons.protocol_engine.commands.command import DefinedErrorData
from opentrons.protocol_engine.commands.pipetting_common import (
LiquidNotFoundError,
OverpressureError,
OverpressureErrorInternalData,
)
from opentrons.types import MountType, Mount as HwMount, Point

from .. import commands
from .. import errors
from ..types import (
LoadedPipette,
Expand All @@ -34,31 +32,6 @@
CurrentPipetteLocation,
TipGeometry,
)
from ..commands import (
LoadPipetteResult,
AspirateResult,
AspirateInPlaceResult,
DispenseResult,
DispenseInPlaceResult,
MoveLabwareResult,
MoveToCoordinatesResult,
MoveToWellResult,
MoveRelativeResult,
MoveToAddressableAreaResult,
MoveToAddressableAreaForDropTipResult,
PickUpTipResult,
DropTipResult,
DropTipInPlaceResult,
HomeResult,
RetractAxisResult,
BlowOutResult,
BlowOutInPlaceResult,
unsafe,
TouchTipResult,
thermocycler,
heater_shaker,
PrepareToAspirateResult,
)
from ..commands.configuring_common import (
PipetteConfigUpdateResultMixin,
PipetteNozzleLayoutResultMixin,
Expand Down Expand Up @@ -227,7 +200,7 @@ def _handle_command( # noqa: C901
private_result.pipette_id
] = private_result.nozzle_map

if isinstance(command.result, LoadPipetteResult):
if isinstance(command.result, commands.LoadPipetteResult):
pipette_id = command.result.pipetteId

self._state.pipettes_by_id[pipette_id] = LoadedPipette(
Expand All @@ -247,7 +220,7 @@ def _handle_command( # noqa: C901
pipette_id
] = static_config.default_nozzle_map

elif isinstance(command.result, PickUpTipResult):
elif isinstance(command.result, commands.PickUpTipResult):
pipette_id = command.params.pipetteId
attached_tip = TipGeometry(
length=command.result.tipLength,
Expand Down Expand Up @@ -281,7 +254,11 @@ def _handle_command( # noqa: C901

elif isinstance(
command.result,
(DropTipResult, DropTipInPlaceResult, unsafe.UnsafeDropTipInPlaceResult),
(
commands.DropTipResult,
commands.DropTipInPlaceResult,
commands.unsafe.UnsafeDropTipInPlaceResult,
),
):
pipette_id = command.params.pipetteId
self._state.aspirated_volume_by_id[pipette_id] = None
Expand All @@ -307,25 +284,36 @@ def _update_current_location( # noqa: C901
if isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
MoveToWellResult,
PickUpTipResult,
DropTipResult,
AspirateResult,
DispenseResult,
BlowOutResult,
TouchTipResult,
commands.MoveToWellResult,
commands.PickUpTipResult,
commands.DropTipResult,
commands.AspirateResult,
commands.DispenseResult,
commands.BlowOutResult,
commands.TouchTipResult,
commands.LiquidProbeResult,
commands.TryLiquidProbeResult,
),
):
self._state.current_location = CurrentWell(
pipette_id=action.command.params.pipetteId,
labware_id=action.command.params.labwareId,
well_name=action.command.params.wellName,
)
elif (
isinstance(action, FailCommandAction)
and isinstance(action.running_command, (Aspirate, Dispense))
and isinstance(action.error, DefinedErrorData)
and isinstance(action.error.public, OverpressureError)
elif isinstance(action, FailCommandAction) and (
isinstance(action.error, DefinedErrorData)
and (
(
isinstance(
action.running_command, (commands.Aspirate, commands.Dispense)
)
and isinstance(action.error.public, OverpressureError)
)
or (
isinstance(action.running_command, commands.LiquidProbe)
and isinstance(action.error.public, LiquidNotFoundError)
)
)
):
self._state.current_location = CurrentWell(
pipette_id=action.running_command.params.pipetteId,
Expand All @@ -334,7 +322,10 @@ def _update_current_location( # noqa: C901
)
elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(MoveToAddressableAreaResult, MoveToAddressableAreaForDropTipResult),
(
commands.MoveToAddressableAreaResult,
commands.MoveToAddressableAreaForDropTipResult,
),
):
self._state.current_location = CurrentAddressableArea(
pipette_id=action.command.params.pipetteId,
Expand All @@ -349,11 +340,11 @@ def _update_current_location( # noqa: C901
elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
HomeResult,
RetractAxisResult,
MoveToCoordinatesResult,
thermocycler.OpenLidResult,
thermocycler.CloseLidResult,
commands.HomeResult,
commands.RetractAxisResult,
commands.MoveToCoordinatesResult,
commands.thermocycler.OpenLidResult,
commands.thermocycler.CloseLidResult,
),
):
self._state.current_location = None
Expand All @@ -363,8 +354,8 @@ def _update_current_location( # noqa: C901
elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
heater_shaker.SetAndWaitForShakeSpeedResult,
heater_shaker.OpenLabwareLatchResult,
commands.heater_shaker.SetAndWaitForShakeSpeedResult,
commands.heater_shaker.OpenLabwareLatchResult,
),
):
if action.command.result.pipetteRetracted:
Expand All @@ -377,7 +368,7 @@ def _update_current_location( # noqa: C901
# This is necessary for safe motion planning in case the next movement
# goes to the same labware (now in a new place).
elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result, MoveLabwareResult
action.command.result, commands.MoveLabwareResult
):
moved_labware_id = action.command.params.labwareId
if action.command.params.strategy == "usingGripper":
Expand All @@ -398,17 +389,17 @@ def _update_deck_point(
if isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
MoveToWellResult,
MoveToCoordinatesResult,
MoveRelativeResult,
MoveToAddressableAreaResult,
MoveToAddressableAreaForDropTipResult,
PickUpTipResult,
DropTipResult,
AspirateResult,
DispenseResult,
BlowOutResult,
TouchTipResult,
commands.MoveToWellResult,
commands.MoveToCoordinatesResult,
commands.MoveRelativeResult,
commands.MoveToAddressableAreaResult,
commands.MoveToAddressableAreaForDropTipResult,
commands.PickUpTipResult,
commands.DropTipResult,
commands.AspirateResult,
commands.DispenseResult,
commands.BlowOutResult,
commands.TouchTipResult,
),
):
pipette_id = action.command.params.pipetteId
Expand All @@ -421,7 +412,12 @@ def _update_deck_point(
isinstance(action, FailCommandAction)
and isinstance(
action.running_command,
(Aspirate, Dispense, AspirateInPlace, DispenseInPlace),
(
commands.Aspirate,
commands.Dispense,
commands.AspirateInPlace,
commands.DispenseInPlace,
),
)
and isinstance(action.error, DefinedErrorData)
and isinstance(action.error.public, OverpressureError)
Expand All @@ -437,26 +433,26 @@ def _update_deck_point(
elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
HomeResult,
RetractAxisResult,
thermocycler.OpenLidResult,
thermocycler.CloseLidResult,
commands.HomeResult,
commands.RetractAxisResult,
commands.thermocycler.OpenLidResult,
commands.thermocycler.CloseLidResult,
),
):
self._clear_deck_point()

elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(
heater_shaker.SetAndWaitForShakeSpeedResult,
heater_shaker.OpenLabwareLatchResult,
commands.heater_shaker.SetAndWaitForShakeSpeedResult,
commands.heater_shaker.OpenLabwareLatchResult,
),
):
if action.command.result.pipetteRetracted:
self._clear_deck_point()

elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result, MoveLabwareResult
action.command.result, commands.MoveLabwareResult
):
if action.command.params.strategy == "usingGripper":
# All mounts will have been retracted.
Expand All @@ -466,7 +462,8 @@ def _update_volumes(
self, action: Union[SucceedCommandAction, FailCommandAction]
) -> None:
if isinstance(action, SucceedCommandAction) and isinstance(
action.command.result, (AspirateResult, AspirateInPlaceResult)
action.command.result,
(commands.AspirateResult, commands.AspirateInPlaceResult),
):
pipette_id = action.command.params.pipetteId
previous_volume = self._state.aspirated_volume_by_id[pipette_id] or 0
Expand All @@ -477,7 +474,8 @@ def _update_volumes(
self._state.aspirated_volume_by_id[pipette_id] = next_volume

elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result, (DispenseResult, DispenseInPlaceResult)
action.command.result,
(commands.DispenseResult, commands.DispenseInPlaceResult),
):
pipette_id = action.command.params.pipetteId
previous_volume = self._state.aspirated_volume_by_id[pipette_id] or 0
Expand All @@ -488,13 +486,17 @@ def _update_volumes(

elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result,
(BlowOutResult, BlowOutInPlaceResult, unsafe.UnsafeBlowOutInPlaceResult),
(
commands.BlowOutResult,
commands.BlowOutInPlaceResult,
commands.unsafe.UnsafeBlowOutInPlaceResult,
),
):
pipette_id = action.command.params.pipetteId
self._state.aspirated_volume_by_id[pipette_id] = None

elif isinstance(action, SucceedCommandAction) and isinstance(
action.command.result, PrepareToAspirateResult
action.command.result, commands.PrepareToAspirateResult
):
pipette_id = action.command.params.pipetteId
self._state.aspirated_volume_by_id[pipette_id] = 0
Expand Down
Loading

0 comments on commit a2b5c44

Please sign in to comment.