Skip to content

Commit 914c567

Browse files
sanni-tecormany
andauthored
fix(api, shared-data): raise error when using gripper in ot2 protocols (#13208)
* raise error if using gripper with ot2 robot type * add new error code for NOT_SUPPORTED_ON_ROBOT_TYPE --------- Co-authored-by: Ed Cormany <[email protected]>
1 parent a8bf9c0 commit 914c567

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

api/src/opentrons/protocol_engine/commands/move_labware.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
LabwareOffsetVector,
1313
LabwareMovementOffsetData,
1414
)
15-
from ..errors import LabwareMovementNotAllowedError
15+
from ..errors import LabwareMovementNotAllowedError, NotSupportedOnRobotType
1616
from ..resources import labware_validation
1717
from .command import AbstractCommandImpl, BaseCommand, BaseCommandCreate
1818

@@ -120,6 +120,11 @@ async def execute(self, params: MoveLabwareParams) -> MoveLabwareResult:
120120
)
121121

122122
if params.strategy == LabwareMovementStrategy.USING_GRIPPER:
123+
if self._state_view.config.robot_type == "OT-2 Standard":
124+
raise NotSupportedOnRobotType(
125+
message="Labware movement using a gripper is not supported on the OT-2",
126+
details={"strategy": params.strategy},
127+
)
123128
if labware_validation.validate_definition_is_adapter(
124129
current_labware_definition
125130
):

api/src/opentrons/protocol_engine/errors/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
LabwareMovementNotAllowedError,
5555
LocationIsOccupiedError,
5656
InvalidAxisForRobotType,
57+
NotSupportedOnRobotType,
5758
)
5859

5960
from .error_occurrence import ErrorOccurrence, ProtocolCommandFailedError
@@ -114,6 +115,7 @@
114115
"LabwareMovementNotAllowedError",
115116
"LocationIsOccupiedError",
116117
"InvalidAxisForRobotType",
118+
"NotSupportedOnRobotType",
117119
# error occurrence models
118120
"ErrorOccurrence",
119121
]

api/src/opentrons/protocol_engine/errors/exceptions.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ def __init__(
684684
wrapping: Optional[Sequence[EnumeratedError]] = None,
685685
) -> None:
686686
"""Build a HardwareNotSupportedError."""
687-
super().__init__(ErrorCodes.GENERAL_ERROR, message, details, wrapping)
687+
super().__init__(
688+
ErrorCodes.NOT_SUPPORTED_ON_ROBOT_TYPE, message, details, wrapping
689+
)
688690

689691

690692
class GripperNotAttachedError(ProtocolEngineError):
@@ -789,3 +791,18 @@ def __init__(
789791
) -> None:
790792
"""Build an EStopActivatedError."""
791793
super().__init__(ErrorCodes.E_STOP_ACTIVATED, message, details, wrapping)
794+
795+
796+
class NotSupportedOnRobotType(ProtocolEngineError):
797+
"""Raised when attempting to perform an action that is not supported for the given robot type."""
798+
799+
def __init__(
800+
self,
801+
message: Optional[str] = None,
802+
details: Optional[Dict[str, Any]] = None,
803+
wrapping: Optional[Sequence[EnumeratedError]] = None,
804+
) -> None:
805+
"""Build a NotSupportedOnRobotType exception."""
806+
super().__init__(
807+
ErrorCodes.NOT_SUPPORTED_ON_ROBOT_TYPE, message, details, wrapping
808+
)

api/tests/opentrons/protocol_engine/commands/test_move_labware.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from opentrons.types import DeckSlotName
77
from opentrons.protocols.models import LabwareDefinition
8-
from opentrons.protocol_engine import errors
8+
from opentrons.protocol_engine import errors, Config
99
from opentrons.protocol_engine.resources import labware_validation
1010
from opentrons.protocol_engine.types import (
1111
DeckSlotLocation,
@@ -15,6 +15,7 @@
1515
LabwareMovementStrategy,
1616
LabwareOffsetVector,
1717
LabwareMovementOffsetData,
18+
DeckType,
1819
)
1920
from opentrons.protocol_engine.state import StateView
2021
from opentrons.protocol_engine.commands.move_labware import (
@@ -424,3 +425,44 @@ async def test_move_labware_raises_when_moving_adapter_with_gripper(
424425

425426
with pytest.raises(errors.LabwareMovementNotAllowedError, match="gripper"):
426427
await subject.execute(data)
428+
429+
430+
async def test_move_labware_with_gripper_raises_on_ot2(
431+
decoy: Decoy,
432+
equipment: EquipmentHandler,
433+
labware_movement: LabwareMovementHandler,
434+
state_view: StateView,
435+
run_control: RunControlHandler,
436+
) -> None:
437+
"""It should raise an error when using a gripper with robot type of OT2."""
438+
subject = MoveLabwareImplementation(
439+
state_view=state_view,
440+
equipment=equipment,
441+
labware_movement=labware_movement,
442+
run_control=run_control,
443+
)
444+
data = MoveLabwareParams(
445+
labwareId="my-cool-labware-id",
446+
newLocation=DeckSlotLocation(slotName=DeckSlotName.SLOT_4),
447+
strategy=LabwareMovementStrategy.USING_GRIPPER,
448+
)
449+
decoy.when(state_view.labware.get(labware_id="my-cool-labware-id")).then_return(
450+
LoadedLabware(
451+
id="my-cool-labware-id",
452+
loadName="load-name",
453+
definitionUri="opentrons-test/load-name/1",
454+
location=DeckSlotLocation(slotName=DeckSlotName.SLOT_4),
455+
offsetId=None,
456+
)
457+
)
458+
decoy.when(
459+
state_view.labware.get_definition(labware_id="my-cool-labware-id")
460+
).then_return(
461+
LabwareDefinition.construct(namespace="spacename") # type: ignore[call-arg]
462+
)
463+
464+
decoy.when(state_view.config).then_return(
465+
Config(robot_type="OT-2 Standard", deck_type=DeckType.OT2_STANDARD)
466+
)
467+
with pytest.raises(errors.NotSupportedOnRobotType):
468+
await subject.execute(data)

shared-data/errors/definitions/1/errors.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@
157157
"4002": {
158158
"detail": "API Removed",
159159
"category": "generalError"
160+
},
161+
"4003": {
162+
"detail": "Not supported on this robot type",
163+
"category": "generalError"
160164
}
161165
}
162166
}

shared-data/python/opentrons_shared_data/errors/codes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ErrorCodes(Enum):
6969
GENERAL_ERROR = _code_from_dict_entry("4000")
7070
ROBOT_IN_USE = _code_from_dict_entry("4001")
7171
API_REMOVED = _code_from_dict_entry("4002")
72+
NOT_SUPPORTED_ON_ROBOT_TYPE = _code_from_dict_entry("4003")
7273

7374
@classmethod
7475
@lru_cache(25)

0 commit comments

Comments
 (0)