Skip to content

Commit

Permalink
refactor(can): Hardware 32 bit move vals (#8662)
Browse files Browse the repository at this point in the history
* convert duration, velocity, and acceleration to 32-bit

* use 32-bit values for motion now that CanFD works.

* change frequency of interrupt.

* fix clock.
  • Loading branch information
amitlissack authored Nov 8, 2021
1 parent bed6a2b commit d616b17
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
11 changes: 3 additions & 8 deletions hardware/opentrons_hardware/drivers/can_bus/messages/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,15 @@ class AddToMoveGroupRequestPayload(MoveGroupRequestPayload):
"""Base of add to move group request to a message group."""

seq_id: utils.UInt8Field
# TODO (al, 2021-10-2021): this should be 32 bits
duration: utils.UInt16Field
duration: utils.UInt32Field


@dataclass
class AddLinearMoveRequestPayload(AddToMoveGroupRequestPayload):
"""Add a linear move request to a message group."""

# TODO (al, 2021-10-2021): this should be 32 bits
acceleration: utils.Int16Field
# TODO (al, 2021-10-2021): this should be 32 bits
velocity: utils.Int16Field
# TODO (al, 2021-10-2021): this should be present and 32 bits
# position: utils.UInt32Field
acceleration: utils.Int32Field
velocity: utils.Int32Field


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion hardware/opentrons_hardware/hardware_control/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from typing_extensions import Final


interrupts_per_sec: Final = 8500000
interrupts_per_sec: Final = 170000
"""The number of motor interrupts per second."""
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from opentrons_hardware.hardware_control.constants import interrupts_per_sec
from opentrons_hardware.hardware_control.motion import MoveGroups
from opentrons_hardware.utils import UInt8Field, UInt16Field, Int16Field
from opentrons_hardware.utils import UInt8Field, UInt32Field, Int32Field


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,11 +68,11 @@ async def _send_groups(self, can_messenger: CanMessenger) -> None:
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(group_i),
seq_id=UInt8Field(seq_i),
duration=UInt16Field(
duration=UInt32Field(
int(step.duration_sec * interrupts_per_sec)
),
acceleration=Int16Field(0),
velocity=Int16Field(
acceleration=Int32Field(0),
velocity=Int32Field(
int(interrupts_per_sec * step.velocity_mm_sec)
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
message_definitions as md,
MessageDefinition,
)
from opentrons_hardware.utils import UInt8Field, Int16Field, UInt16Field
from opentrons_hardware.utils import UInt8Field, Int32Field, UInt32Field


@pytest.fixture
Expand Down Expand Up @@ -129,14 +129,14 @@ async def test_single_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(0),
seq_id=UInt8Field(0),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_single[0][0][NodeId.head].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_single[0][0][NodeId.head].duration_sec
* interrupts_per_sec
Expand All @@ -161,14 +161,14 @@ async def test_multi_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(0),
seq_id=UInt8Field(0),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_multiple[0][0][NodeId.head].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[0][0][NodeId.head].duration_sec
* interrupts_per_sec
Expand All @@ -185,14 +185,14 @@ async def test_multi_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(1),
seq_id=UInt8Field(0),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_multiple[1][0][NodeId.gantry_x].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[1][0][NodeId.gantry_x].duration_sec
* interrupts_per_sec
Expand All @@ -208,14 +208,14 @@ async def test_multi_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(1),
seq_id=UInt8Field(0),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_multiple[1][0][NodeId.gantry_y].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[1][0][NodeId.gantry_y].duration_sec
* interrupts_per_sec
Expand All @@ -232,14 +232,14 @@ async def test_multi_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(2),
seq_id=UInt8Field(0),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_multiple[2][0][NodeId.pipette].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[2][0][NodeId.pipette].duration_sec
* interrupts_per_sec
Expand All @@ -255,14 +255,14 @@ async def test_multi_send_setup_commands(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(2),
seq_id=UInt8Field(1),
velocity=Int16Field(
velocity=Int32Field(
int(
move_group_multiple[2][1][NodeId.pipette].velocity_mm_sec
* interrupts_per_sec
)
),
acceleration=Int16Field(0),
duration=UInt16Field(
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[2][1][NodeId.pipette].duration_sec
* interrupts_per_sec
Expand Down

0 comments on commit d616b17

Please sign in to comment.