Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
feat(hardware): update Gripper CAN messages (Opentrons#10161)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau authored May 2, 2022
1 parent 6b77e75 commit cfd2a33
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,16 @@ class SetBrushedMotorPwmRequest: # noqa: D101


@dataclass
class GripperGripRequest(EmptyPayloadMessage): # noqa: D101
class GripperGripRequest: # noqa: D101
payload: payloads.GripperMoveRequestPayload
payload_type: Type[BinarySerializable] = payloads.GripperMoveRequestPayload
message_id: Literal[MessageId.gripper_grip_request] = MessageId.gripper_grip_request


@dataclass
class GripperHomeRequest(EmptyPayloadMessage): # noqa: D101
class GripperHomeRequest: # noqa: D101
payload: payloads.GripperMoveRequestPayload
payload_type: Type[BinarySerializable] = payloads.GripperMoveRequestPayload
message_id: Literal[MessageId.gripper_home_request] = MessageId.gripper_home_request


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ class GripperInfoResponsePayload(utils.BinarySerializable):
gripper_serial: GripperSerialField


@dataclass
class GripperMoveRequestPayload(AddToMoveGroupRequestPayload):
"""A request to move gripper."""

freq: utils.UInt32Field
duty_cycle: utils.UInt32Field


@dataclass
class TipActionRequestPayload(AddToMoveGroupRequestPayload):
"""A request to perform a tip action."""

Expand Down
36 changes: 31 additions & 5 deletions hardware/opentrons_hardware/hardware_control/gripper_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GripperGripRequest,
GripperHomeRequest,
)
from opentrons_hardware.firmware_bindings.utils import UInt32Field
from opentrons_hardware.firmware_bindings.utils import UInt8Field, UInt32Field
from opentrons_hardware.firmware_bindings.constants import NodeId


Expand Down Expand Up @@ -42,11 +42,37 @@ async def set_pwm_param(
)


async def grip(can_messenger: CanMessenger) -> None:
async def grip(
can_messenger: CanMessenger, group_id: int, seq_id: int, freq: int, duty_cycle: int
) -> None:
"""Start grip motion."""
await can_messenger.send(node_id=NodeId.gripper, message=GripperGripRequest())
await can_messenger.send(
node_id=NodeId.gripper,
message=GripperGripRequest(
payload=payloads.GripperMoveRequestPayload(
group_id=UInt8Field(group_id),
seq_id=UInt8Field(seq_id),
duration=UInt32Field(0),
freq=UInt32Field(freq),
duty_cycle=UInt32Field(duty_cycle),
)
),
)


async def home(can_messenger: CanMessenger) -> None:
async def home(
can_messenger: CanMessenger, group_id: int, seq_id: int, freq: int, duty_cycle: int
) -> None:
"""Start home motion."""
await can_messenger.send(node_id=NodeId.gripper, message=GripperHomeRequest())
await can_messenger.send(
node_id=NodeId.gripper,
message=GripperHomeRequest(
payload=payloads.GripperMoveRequestPayload(
group_id=UInt8Field(group_id),
seq_id=UInt8Field(seq_id),
duration=UInt32Field(0),
freq=UInt32Field(freq),
duty_cycle=UInt32Field(duty_cycle),
)
),
)
24 changes: 22 additions & 2 deletions hardware/opentrons_hardware/scripts/gripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from typing import Callable
from logging.config import dictConfig
from opentrons_hardware.firmware_bindings.messages import payloads
from opentrons_hardware.firmware_bindings.messages.message_definitions import (
SetupRequest,
DisableMotorRequest,
ExecuteMoveGroupRequest,
)
from opentrons_hardware.drivers.can_bus.can_messenger import CanMessenger
from opentrons_hardware.firmware_bindings.constants import NodeId
Expand All @@ -20,6 +22,8 @@
grip,
home,
)
from opentrons_hardware.firmware_bindings.utils import UInt8Field


GetInputFunc = Callable[[str], str]
OutputFunc = Callable[[str], None]
Expand Down Expand Up @@ -56,6 +60,20 @@ def in_green(s: str) -> str:
return f"\033[92m{str(s)}\033[0m"


async def execute_move(messenger: CanMessenger) -> None:
"""Send an execute move command."""
await messenger.send(
node_id=NodeId.broadcast,
message=ExecuteMoveGroupRequest(
payload=payloads.ExecuteMoveGroupRequestPayload(
group_id=UInt8Field(0),
start_trigger=UInt8Field(0),
cancel_trigger=UInt8Field(0),
)
),
)


def output_details(i: int, freq: int, duty_cycle: int, v_ref: float) -> None:
"""Print out test details."""
print(f"\n\033[95mRound {i}:\033[0m")
Expand Down Expand Up @@ -88,11 +106,13 @@ async def run(args: argparse.Namespace) -> None:

input(in_green("Press Enter to grip...\n"))

await grip(messenger)
await grip(messenger, 0, 0, 0, 0)
await execute_move(messenger)

input(in_green("Press Enter to release...\n"))

await home(messenger)
await home(messenger, 0, 0, 0, 0)
await execute_move(messenger)

except asyncio.CancelledError:
pass
Expand Down
27 changes: 25 additions & 2 deletions hardware/opentrons_hardware/scripts/gripper_currents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from opentrons_hardware.firmware_bindings.messages.message_definitions import (
SetupRequest,
DisableMotorRequest,
ExecuteMoveGroupRequest,
)
from opentrons_hardware.firmware_bindings.messages.payloads import (
ExecuteMoveGroupRequestPayload,
)
from opentrons_hardware.drivers.can_bus.can_messenger import CanMessenger
from opentrons_hardware.firmware_bindings.constants import NodeId
Expand All @@ -20,6 +24,9 @@
grip,
home,
)
from opentrons_hardware.firmware_bindings.utils import (
UInt8Field,
)

GetInputFunc = Callable[[str], str]
OutputFunc = Callable[[str], None]
Expand Down Expand Up @@ -52,6 +59,20 @@ def in_green(s: str) -> str:
return f"\033[92m{str(s)}\033[0m"


async def execute_move(messenger: CanMessenger) -> None:
"""Send an execute move command."""
await messenger.send(
node_id=NodeId.broadcast,
message=ExecuteMoveGroupRequest(
payload=ExecuteMoveGroupRequestPayload(
group_id=UInt8Field(0),
start_trigger=UInt8Field(0),
cancel_trigger=UInt8Field(0),
)
),
)


async def run(args: argparse.Namespace) -> None:
"""Entry point for script."""
os.system("cls")
Expand Down Expand Up @@ -80,11 +101,13 @@ async def run(args: argparse.Namespace) -> None:

input(in_green("Press Enter to grip...\n"))

await grip(messenger)
await grip(messenger, 0, 0, 0, 0)
await execute_move(messenger)

input(in_green("Press Enter to release...\n"))

await home(messenger)
await home(messenger, 0, 0, 0, 0)
await execute_move(messenger)

except asyncio.CancelledError:
pass
Expand Down

0 comments on commit cfd2a33

Please sign in to comment.