Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): RobotContext add run log commands #17040

Open
wants to merge 1 commit into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions api/src/opentrons/legacy_commands/robot_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from opentrons.types import Location, Mount, AxisMapType
from .helpers import stringify_location
from . import types as command_types
from typing import Optional


def move_to(
mount: Mount, location: Location, speed: Optional[float]
) -> command_types.RobotMoveToCommand:
location_text = stringify_location(location)
text = f"Moving to {location_text} at {speed}"
return {
"name": command_types.ROBOT_MOVE_TO,
"payload": {"mount": mount, "location": location, "text": text},
}


def move_axis_to(
axis_map: AxisMapType, speed: Optional[float]
) -> command_types.RobotMoveAxisToCommand:
text = f"Moving to the provided absolute axis map {axis_map} at {speed}."
return {
"name": command_types.ROBOT_MOVE_AXES_TO,
"payload": {"absolute_axes": axis_map, "text": text},
}


def move_axis_relative(
axis_map: AxisMapType, speed: Optional[float]
) -> command_types.RobotMoveAxisRelativeCommand:
text = f"Moving to the provided relative axis map {axis_map} as {speed}"
return {
"name": command_types.ROBOT_MOVE_RELATIVE_TO,
"payload": {"relative_axes": axis_map, "text": text},
}


def open_gripper() -> command_types.RobotOpenGripperJawCommand:
text = "Opening the gripper jaw."
return {
"name": command_types.ROBOT_OPEN_GRIPPER_JAW,
"payload": {"text": text},
}


def close_gripper(force: Optional[float]) -> command_types.RobotCloseGripperJawCommand:
text = f"Closing the gripper jaw with force {force}."
return {
"name": command_types.ROBOT_CLOSE_GRIPPER_JAW,
"payload": {"text": text},
}
91 changes: 90 additions & 1 deletion api/src/opentrons/legacy_commands/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from opentrons.protocol_api.labware import Well
from opentrons.protocol_api.disposal_locations import TrashBin, WasteChute

from opentrons.types import Location
from opentrons.types import Location, Mount, AxisMapType


# type for subscriptions
Expand Down Expand Up @@ -78,6 +78,13 @@
THERMOCYCLER_DEACTIVATE_LID: Final = "command.THERMOCYCLER_DEACTIVATE_LID"
THERMOCYCLER_DEACTIVATE_BLOCK: Final = "command.THERMOCYCLER_DEACTIVATE_BLOCK"

# Robot #
ROBOT_MOVE_TO: Final = "command.ROBOT_MOVE_TO"
ROBOT_MOVE_AXES_TO: Final = "command.ROBOT_MOVE_AXES_TO"
ROBOT_MOVE_RELATIVE_TO: Final = "command.ROBOT_MOVE_RELATIVE_TO"
ROBOT_OPEN_GRIPPER_JAW: Final = "command.ROBOT_OPEN_GRIPPER_JAW"
ROBOT_CLOSE_GRIPPER_JAW: Final = "command.ROBOT_CLOSE_GRIPPER_JAW"


class TextOnlyPayload(TypedDict):
text: str
Expand Down Expand Up @@ -540,6 +547,51 @@ class MoveLabwareCommand(TypedDict):
payload: MoveLabwareCommandPayload


# Robot Commands and Payloads


class GripperCommandPayload(TextOnlyPayload):
pass


class RobotMoveToCommandPayload(TextOnlyPayload):
location: Location
mount: Mount


class RobotMoveAxisToCommandPayload(TextOnlyPayload):
absolute_axes: AxisMapType


class RobotMoveAxisRelativeCommandPayload(TextOnlyPayload):
relative_axes: AxisMapType


class RobotMoveToCommand(TypedDict):
name: Literal["command.ROBOT_MOVE_TO"]
payload: RobotMoveToCommandPayload


class RobotMoveAxisToCommand(TypedDict):
name: Literal["command.ROBOT_MOVE_AXES_TO"]
payload: RobotMoveAxisToCommandPayload


class RobotMoveAxisRelativeCommand(TypedDict):
name: Literal["command.ROBOT_MOVE_RELATIVE_TO"]
payload: RobotMoveAxisRelativeCommandPayload


class RobotOpenGripperJawCommand(TypedDict):
name: Literal["command.ROBOT_OPEN_GRIPPER_JAW"]
payload: GripperCommandPayload


class RobotCloseGripperJawCommand(TypedDict):
name: Literal["command.ROBOT_CLOSE_GRIPPER_JAW"]
payload: GripperCommandPayload


Command = Union[
DropTipCommand,
DropTipInDisposalLocationCommand,
Expand Down Expand Up @@ -588,6 +640,12 @@ class MoveLabwareCommand(TypedDict):
MoveToCommand,
MoveToDisposalLocationCommand,
MoveLabwareCommand,
# Robot commands
RobotMoveToCommand,
RobotMoveAxisToCommand,
RobotMoveAxisRelativeCommand,
RobotOpenGripperJawCommand,
RobotCloseGripperJawCommand,
]


Expand Down Expand Up @@ -637,6 +695,11 @@ class MoveLabwareCommand(TypedDict):
MoveToCommandPayload,
MoveToDisposalLocationCommandPayload,
MoveLabwareCommandPayload,
# Robot payloads
RobotMoveToCommandPayload,
RobotMoveAxisRelativeCommandPayload,
RobotMoveAxisToCommandPayload,
GripperCommandPayload,
]


Expand Down Expand Up @@ -877,6 +940,26 @@ class MoveLabwareMessage(CommandMessageFields, MoveLabwareCommand):
pass


class RobotMoveToMessage(CommandMessageFields, RobotMoveToCommand):
pass


class RobotMoveAxisToMessage(CommandMessageFields, RobotMoveAxisToCommand):
pass


class RobotMoveAxisRelativeMessage(CommandMessageFields, RobotMoveAxisRelativeCommand):
pass


class RobotOpenGripperJawMessage(CommandMessageFields, RobotOpenGripperJawCommand):
pass


class RobotCloseGripperJawMessage(CommandMessageFields, RobotCloseGripperJawCommand):
pass


CommandMessage = Union[
DropTipMessage,
DropTipInDisposalLocationMessage,
Expand Down Expand Up @@ -924,4 +1007,10 @@ class MoveLabwareMessage(CommandMessageFields, MoveLabwareCommand):
MoveToMessage,
MoveToDisposalLocationMessage,
MoveLabwareMessage,
# Robot Messages
RobotMoveToMessage,
RobotMoveAxisToMessage,
RobotMoveAxisRelativeMessage,
RobotOpenGripperJawMessage,
RobotCloseGripperJawMessage,
]
1 change: 1 addition & 0 deletions api/src/opentrons/protocol_api/protocol_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(
core=self._core.load_robot(),
protocol_core=self._core,
api_version=self._api_version,
broker=broker,
)
except APIVersionError:
self._robot = None
Expand Down
54 changes: 48 additions & 6 deletions api/src/opentrons/protocol_api/robot_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
AxisType,
StringAxisMap,
)
from opentrons.legacy_broker import LegacyBroker
from opentrons.legacy_commands import robot_commands as cmds
from opentrons.legacy_commands import publisher
from opentrons.hardware_control import SyncHardwareAPI
from opentrons.protocols.api_support.util import requires_version
Expand Down Expand Up @@ -49,8 +51,13 @@ class RobotContext(publisher.CommandPublisher):
"""

def __init__(
self, core: RobotCore, protocol_core: ProtocolCore, api_version: APIVersion
self,
core: RobotCore,
protocol_core: ProtocolCore,
api_version: APIVersion,
broker: Optional[LegacyBroker] = None,
) -> None:
super().__init__(broker)
self._hardware = HardwareManager(hardware=protocol_core.get_hardware())
self._core = core
self._protocol_core = protocol_core
Expand Down Expand Up @@ -87,7 +94,16 @@ def move_to(
:param speed:
"""
mount = validation.ensure_instrument_mount(mount)
self._core.move_to(mount, destination.point, speed)
with publisher.publish_context(
broker=self.broker,
command=cmds.move_to(
# This needs to be called from protocol context and not the command for import loop reasons
mount=mount,
location=destination,
speed=speed,
),
):
self._core.move_to(mount, destination.point, speed)

@requires_version(2, 22)
def move_axes_to(
Expand Down Expand Up @@ -119,7 +135,15 @@ def move_axes_to(
)
else:
critical_point = None
self._core.move_axes_to(axis_map, critical_point, speed)
with publisher.publish_context(
broker=self.broker,
command=cmds.move_axis_to(
# This needs to be called from protocol context and not the command for import loop reasons
axis_map=axis_map,
speed=speed,
),
):
self._core.move_axes_to(axis_map, critical_point, speed)

@requires_version(2, 22)
def move_axes_relative(
Expand All @@ -142,15 +166,33 @@ def move_axes_relative(
axis_map = validation.ensure_axis_map_type(
axis_map, self._protocol_core.robot_type, is_96_channel
)
self._core.move_axes_relative(axis_map, speed)
with publisher.publish_context(
broker=self.broker,
command=cmds.move_axis_relative(
# This needs to be called from protocol context and not the command for import loop reasons
axis_map=axis_map,
speed=speed,
),
):
self._core.move_axes_relative(axis_map, speed)

def close_gripper_jaw(self, force: Optional[float] = None) -> None:
"""Command the gripper closed with some force."""
self._core.close_gripper(force)
with publisher.publish_context(
broker=self.broker,
command=cmds.close_gripper(
force=force,
),
):
self._core.close_gripper(force)

def open_gripper_jaw(self) -> None:
"""Command the gripper open."""
self._core.release_grip()
with publisher.publish_context(
broker=self.broker,
command=cmds.open_gripper(),
):
self._core.release_grip()

def axis_coordinates_for(
self,
Expand Down
Loading