-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(robot-context): Add gripper commands
- Loading branch information
1 parent
6800486
commit 736370a
Showing
10 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
api/src/opentrons/protocol_engine/commands/robot/close_gripper_jaw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Command models for opening a gripper jaw.""" | ||
from __future__ import annotations | ||
from typing import Literal, Type, Optional | ||
from opentrons.hardware_control import HardwareControlAPI | ||
from opentrons.protocol_engine.resources import ensure_ot3_hardware | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from ..command import ( | ||
AbstractCommandImpl, | ||
BaseCommand, | ||
BaseCommandCreate, | ||
SuccessData, | ||
) | ||
from opentrons.protocol_engine.errors.error_occurrence import ErrorOccurrence | ||
|
||
|
||
closeGripperJawCommandType = Literal["robot/closeGripperJaw"] | ||
|
||
|
||
class closeGripperJawParams(BaseModel): | ||
"""Payload required to close a gripper.""" | ||
|
||
force: Optional[float] = Field( | ||
default=None, | ||
description="The force the gripper should use to hold the jaws, falls to default if none is provided.", | ||
) | ||
|
||
|
||
class closeGripperJawResult(BaseModel): | ||
"""Result data from the execution of a closeGripperJaw command.""" | ||
|
||
pass | ||
|
||
|
||
class closeGripperJawImplementation( | ||
AbstractCommandImpl[closeGripperJawParams, SuccessData[closeGripperJawResult]] | ||
): | ||
"""closeGripperJaw command implementation.""" | ||
|
||
def __init__( | ||
self, | ||
hardware_api: HardwareControlAPI, | ||
**kwargs: object, | ||
) -> None: | ||
self._hardware_api = hardware_api | ||
|
||
async def execute( | ||
self, params: closeGripperJawParams | ||
) -> SuccessData[closeGripperJawResult]: | ||
"""Release the gripper.""" | ||
ot3_hardware_api = ensure_ot3_hardware(self._hardware_api) | ||
await ot3_hardware_api.grip(force_newtons=params.force) | ||
return SuccessData( | ||
public=closeGripperJawResult(), | ||
) | ||
|
||
|
||
class closeGripperJaw( | ||
BaseCommand[closeGripperJawParams, closeGripperJawResult, ErrorOccurrence] | ||
): | ||
"""closeGripperJaw command model.""" | ||
|
||
commandType: closeGripperJawCommandType = "robot/closeGripperJaw" | ||
params: closeGripperJawParams | ||
result: Optional[closeGripperJawResult] | ||
|
||
_ImplementationCls: Type[ | ||
closeGripperJawImplementation | ||
] = closeGripperJawImplementation | ||
|
||
|
||
class closeGripperJawCreate(BaseCommandCreate[closeGripperJawParams]): | ||
"""closeGripperJaw command request model.""" | ||
|
||
commandType: closeGripperJawCommandType = "robot/closeGripperJaw" | ||
params: closeGripperJawParams | ||
|
||
_CommandCls: Type[closeGripperJaw] = closeGripperJaw |
77 changes: 77 additions & 0 deletions
77
api/src/opentrons/protocol_engine/commands/robot/open_gripper_jaw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Command models for opening a gripper jaw.""" | ||
from __future__ import annotations | ||
from typing import Literal, Type, Optional | ||
from opentrons.hardware_control import HardwareControlAPI | ||
from opentrons.protocol_engine.resources import ensure_ot3_hardware | ||
|
||
from pydantic import BaseModel | ||
|
||
from ..command import ( | ||
AbstractCommandImpl, | ||
BaseCommand, | ||
BaseCommandCreate, | ||
SuccessData, | ||
) | ||
from opentrons.protocol_engine.errors.error_occurrence import ErrorOccurrence | ||
|
||
|
||
openGripperJawCommandType = Literal["robot/openGripperJaw"] | ||
|
||
|
||
class openGripperJawParams(BaseModel): | ||
"""Payload required to release a gripper.""" | ||
|
||
pass | ||
|
||
|
||
class openGripperJawResult(BaseModel): | ||
"""Result data from the execution of a openGripperJaw command.""" | ||
|
||
pass | ||
|
||
|
||
class openGripperJawImplementation( | ||
AbstractCommandImpl[openGripperJawParams, SuccessData[openGripperJawResult]] | ||
): | ||
"""openGripperJaw command implementation.""" | ||
|
||
def __init__( | ||
self, | ||
hardware_api: HardwareControlAPI, | ||
**kwargs: object, | ||
) -> None: | ||
self._hardware_api = hardware_api | ||
|
||
async def execute( | ||
self, params: openGripperJawParams | ||
) -> SuccessData[openGripperJawResult]: | ||
"""Release the gripper.""" | ||
ot3_hardware_api = ensure_ot3_hardware(self._hardware_api) | ||
|
||
await ot3_hardware_api.home_gripper_jaw() | ||
return SuccessData( | ||
public=openGripperJawResult(), | ||
) | ||
|
||
|
||
class openGripperJaw( | ||
BaseCommand[openGripperJawParams, openGripperJawResult, ErrorOccurrence] | ||
): | ||
"""openGripperJaw command model.""" | ||
|
||
commandType: openGripperJawCommandType = "robot/openGripperJaw" | ||
params: openGripperJawParams | ||
result: Optional[openGripperJawResult] | ||
|
||
_ImplementationCls: Type[ | ||
openGripperJawImplementation | ||
] = openGripperJawImplementation | ||
|
||
|
||
class openGripperJawCreate(BaseCommandCreate[openGripperJawParams]): | ||
"""openGripperJaw command request model.""" | ||
|
||
commandType: openGripperJawCommandType = "robot/openGripperJaw" | ||
params: openGripperJawParams | ||
|
||
_CommandCls: Type[openGripperJaw] = openGripperJaw |
28 changes: 28 additions & 0 deletions
28
api/tests/opentrons/protocol_engine/commands/robot/test_close_gripper_jaw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Test robot.open-gripper-jaw commands.""" | ||
from decoy import Decoy | ||
|
||
from opentrons.hardware_control import OT3HardwareControlAPI | ||
|
||
from opentrons.protocol_engine.commands.command import SuccessData | ||
from opentrons.protocol_engine.commands.robot.close_gripper_jaw import ( | ||
closeGripperJawParams, | ||
closeGripperJawResult, | ||
closeGripperJawImplementation, | ||
) | ||
|
||
|
||
async def test_close_gripper_jaw_implementation( | ||
decoy: Decoy, | ||
ot3_hardware_api: OT3HardwareControlAPI, | ||
) -> None: | ||
"""Test the `robot.closeGripperJaw` implementation.""" | ||
subject = closeGripperJawImplementation( | ||
hardware_api=ot3_hardware_api, | ||
) | ||
|
||
params = closeGripperJawParams(force=10) | ||
|
||
result = await subject.execute(params=params) | ||
|
||
assert result == SuccessData(public=closeGripperJawResult()) | ||
decoy.verify(await ot3_hardware_api.grip(force_newtons=10)) |
28 changes: 28 additions & 0 deletions
28
api/tests/opentrons/protocol_engine/commands/robot/test_open_gripper_jaw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Test robot.open-gripper-jaw commands.""" | ||
from decoy import Decoy | ||
|
||
from opentrons.hardware_control import OT3HardwareControlAPI | ||
|
||
from opentrons.protocol_engine.commands.command import SuccessData | ||
from opentrons.protocol_engine.commands.robot.open_gripper_jaw import ( | ||
openGripperJawParams, | ||
openGripperJawResult, | ||
openGripperJawImplementation, | ||
) | ||
|
||
|
||
async def test_open_gripper_jaw_implementation( | ||
decoy: Decoy, | ||
ot3_hardware_api: OT3HardwareControlAPI, | ||
) -> None: | ||
"""Test the `robot.openGripperJaw` implementation.""" | ||
subject = openGripperJawImplementation( | ||
hardware_api=ot3_hardware_api, | ||
) | ||
|
||
params = openGripperJawParams() | ||
|
||
result = await subject.execute(params=params) | ||
|
||
assert result == SuccessData(public=openGripperJawResult()) | ||
decoy.verify(await ot3_hardware_api.home_gripper_jaw()) |