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

refactor(api,hardware): use new pipette node ids #9363

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_version = "3.7"

[dev-packages]
coverage = "==5.1"
mypy = "0.910"
mypy = "==0.910"
numpydoc = "==0.9.1"
pytest = "==6.1.0"
pytest-aiohttp = "==0.3.0"
Expand Down
621 changes: 298 additions & 323 deletions api/Pipfile.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def _axis_nodes() -> List["NodeId"]:
NodeId.gantry_y,
NodeId.head_l,
NodeId.head_r,
NodeId.pipette,
NodeId.pipette_left,
NodeId.pipette_right,
]

@staticmethod
Expand All @@ -120,7 +121,8 @@ def _axis_to_node(axis: str) -> "NodeId":
"Y": NodeId.gantry_y,
"Z": NodeId.head_l,
"A": NodeId.head_r,
"B": NodeId.pipette,
"B": NodeId.pipette_left,
"C": NodeId.pipette_right,
}
return anm[axis]

Expand All @@ -131,7 +133,8 @@ def _node_to_axis(node: "NodeId") -> str:
NodeId.gantry_y: "Y",
NodeId.head_l: "Z",
NodeId.head_r: "A",
NodeId.pipette: "B",
NodeId.pipette_left: "B",
NodeId.pipette_right: "C",
}
return nam[node]

Expand Down Expand Up @@ -419,5 +422,6 @@ def _get_home_position() -> Dict[NodeId, float]:
NodeId.head_r: 0,
NodeId.gantry_x: 0,
NodeId.gantry_y: 0,
NodeId.pipette: 0,
NodeId.pipette_left: 0,
NodeId.pipette_right: 0,
}
32 changes: 14 additions & 18 deletions api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
Sequence,
Generator,
cast,
Union,
)
from typing_extensions import Literal

from opentrons.config.types import OT3Config
from opentrons.drivers.rpi_drivers.gpio_simulator import SimulatingGPIOCharDev
Expand Down Expand Up @@ -55,7 +53,7 @@
class OT3Simulator:
"""OT3 Hardware Controller Backend."""

_position: Dict[Union[NodeId, Literal["Pipette2"]], float]
_position: Dict[NodeId, float]

@classmethod
async def build(
Expand Down Expand Up @@ -143,31 +141,31 @@ def _node_axes() -> List[str]:
return ["X", "Y", "Z", "A", "B", "C"]

@staticmethod
def _axis_to_node(axis: str) -> Union["NodeId", Literal["Pipette2"]]:
anm: Dict[str, Union["NodeId", Literal["Pipette2"]]] = {
def _axis_to_node(axis: str) -> "NodeId":
anm: Dict[str, "NodeId"] = {
"X": NodeId.gantry_x,
"Y": NodeId.gantry_y,
"Z": NodeId.head_l,
"A": NodeId.head_r,
"B": NodeId.pipette,
"C": "Pipette2",
"B": NodeId.pipette_left,
"C": NodeId.pipette_right,
}
return anm[axis]

@staticmethod
def _node_to_axis(node: Union["NodeId", Literal["Pipette2"]]) -> str:
def _node_to_axis(node: "NodeId") -> str:
nam = {
NodeId.gantry_x: "X",
NodeId.gantry_y: "Y",
NodeId.head_l: "Z",
NodeId.head_r: "A",
NodeId.pipette: "B",
"Pipette2": "C",
NodeId.pipette_left: "B",
NodeId.pipette_right: "C",
}
return nam[node]

@staticmethod
def _node_is_axis(node: Union["NodeId", Literal["Pipette2"]]) -> bool:
def _node_is_axis(node: "NodeId") -> bool:
try:
OT3Simulator._node_to_axis(node)
return True
Expand Down Expand Up @@ -212,9 +210,7 @@ async def update_position(self) -> AxisValueMap:
return self._axis_convert(self._position)

@staticmethod
def _axis_convert(
position: Dict[Union[NodeId, Literal["Pipette2"]], float]
) -> AxisValueMap:
def _axis_convert(position: Dict[NodeId, float]) -> AxisValueMap:
ret: AxisValueMap = {"A": 0, "B": 0, "C": 0, "X": 0, "Y": 0, "Z": 0}
for node, pos in position.items():
# we need to make robot config apply to z or in some other way
Expand Down Expand Up @@ -243,7 +239,7 @@ async def move(
None
"""
log.info(f"move: {target_position}")
target: Dict[Union[NodeId, Literal["Pipette2"]], float] = {}
target: Dict[NodeId, float] = {}
for axis, pos in target_position.items():
if self._axis_is_node(axis):
target[self._axis_to_node(axis)] = pos
Expand Down Expand Up @@ -443,12 +439,12 @@ async def configure_mount(
return None

@staticmethod
def _get_home_position() -> Dict[Union[NodeId, Literal["Pipette2"]], float]:
def _get_home_position() -> Dict[NodeId, float]:
return {
NodeId.head_l: 0,
NodeId.head_r: 0,
NodeId.gantry_x: 0,
NodeId.gantry_y: 0,
NodeId.pipette: 0,
"Pipette2": 0,
NodeId.pipette_left: 0,
NodeId.pipette_right: 0,
}
6 changes: 3 additions & 3 deletions hardware/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions hardware/opentrons_hardware/firmware_update/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""Firmware update package."""

from .initiator import FirmwareUpdateInitiator, head, gantry_y, gantry_x, pipette
from .initiator import (
FirmwareUpdateInitiator,
head,
gantry_y,
gantry_x,
pipette_left,
pipette_right,
)
from .downloader import FirmwareUpdateDownloader
from .hex_file import from_hex_file_path, from_hex_contents, HexRecordProcessor

Expand All @@ -10,7 +17,8 @@
"head",
"gantry_y",
"gantry_x",
"pipette",
"pipette_left",
"pipette_right",
"from_hex_file_path",
"from_hex_contents",
"HexRecordProcessor",
Expand Down
7 changes: 5 additions & 2 deletions hardware/opentrons_hardware/firmware_update/initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class Target:


head: Final = Target(system_node=NodeId.head, bootloader_node=NodeId.head_bootloader)
pipette: Final = Target(
system_node=NodeId.pipette, bootloader_node=NodeId.pipette_bootloader
pipette_left: Final = Target(
system_node=NodeId.pipette_left, bootloader_node=NodeId.pipette_left_bootloader
)
pipette_right: Final = Target(
system_node=NodeId.pipette_right, bootloader_node=NodeId.pipette_right_bootloader
)
gantry_x: Final = Target(
system_node=NodeId.gantry_x, bootloader_node=NodeId.gantry_x_bootloader
Expand Down
6 changes: 4 additions & 2 deletions hardware/opentrons_hardware/hardware_control/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class MoveGroupSingleAxisStep:
NodeId.gantry_y: 50,
NodeId.head_l: 50,
NodeId.head_r: 50,
NodeId.pipette: 2,
NodeId.pipette_left: 2,
NodeId.pipette_right: 2,
}


Expand All @@ -59,7 +60,8 @@ def create(
NodeId.gantry_y,
NodeId.head_r,
NodeId.head_l,
NodeId.pipette,
NodeId.pipette_left,
NodeId.pipette_right,
]
vec = np.array([deltas.get(node, 0) for node in ordered_nodes])
if any(np.isnan(vec)):
Expand Down
6 changes: 4 additions & 2 deletions hardware/opentrons_hardware/scripts/update_fw.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
head,
gantry_x,
gantry_y,
pipette,
pipette_left,
pipette_right,
HexRecordProcessor,
)

Expand Down Expand Up @@ -47,7 +48,8 @@
"head": head,
"gantry-x": gantry_x,
"gantry-y": gantry_y,
"pipette": pipette,
"pipette-left": pipette_left,
"pipette-right": pipette_right,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def test_create_just_head() -> None:
NodeId.head_l: MoveGroupSingleAxisStep(
distance_mm=-2.0, velocity_mm_sec=-0.25, duration_sec=8.0
),
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=0.0, velocity_mm_sec=0.0, duration_sec=8.0
),
NodeId.pipette_right: MoveGroupSingleAxisStep(
distance_mm=0.0, velocity_mm_sec=0.0, duration_sec=8.0
),
},
Expand Down Expand Up @@ -63,7 +66,12 @@ def test_create_just_x_y() -> None:
velocity_mm_sec=0.0,
duration_sec=round(math.sqrt(8) / 0.25, 6),
),
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=round(math.sqrt(8) / 0.25, 6),
),
NodeId.pipette_right: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=round(math.sqrt(8) / 0.25, 6),
Expand Down Expand Up @@ -103,7 +111,12 @@ def test_create_all() -> None:
velocity_mm_sec=0.05 * (4 / math.sqrt(24)),
duration_sec=round(math.sqrt(24) / 0.05, 6),
),
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=round(math.sqrt(24) / 0.05, 6),
),
NodeId.pipette_right: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=round(math.sqrt(24) / 0.05, 6),
Expand Down Expand Up @@ -149,7 +162,12 @@ def test_limit_speeds_single_axis() -> None:
velocity_mm_sec=0.0,
duration_sec=target_duration,
),
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=target_duration,
),
NodeId.pipette_right: MoveGroupSingleAxisStep(
distance_mm=0.0,
velocity_mm_sec=0.0,
duration_sec=target_duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def move_group_multiple() -> MoveGroups:
# Group 2
[
{
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=12, velocity_mm_sec=-23, duration_sec=1234
),
},
{
NodeId.pipette: MoveGroupSingleAxisStep(
NodeId.pipette_left: MoveGroupSingleAxisStep(
distance_mm=12, velocity_mm_sec=23, duration_sec=1234
),
},
Expand Down Expand Up @@ -236,22 +236,22 @@ async def test_multi_send_setup_commands(

# Group 2
mock_can_messenger.send.assert_any_call(
node_id=NodeId.pipette,
node_id=NodeId.pipette_left,
message=AddLinearMoveRequest(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(2),
seq_id=UInt8Field(0),
velocity=Int32Field(
int(
move_group_multiple[2][0][NodeId.pipette].velocity_mm_sec
move_group_multiple[2][0][NodeId.pipette_left].velocity_mm_sec
/ interrupts_per_sec
* (2 ** 31)
)
),
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[2][0][NodeId.pipette].duration_sec
move_group_multiple[2][0][NodeId.pipette_left].duration_sec
* interrupts_per_sec
)
),
Expand All @@ -260,22 +260,22 @@ async def test_multi_send_setup_commands(
)

mock_can_messenger.send.assert_any_call(
node_id=NodeId.pipette,
node_id=NodeId.pipette_left,
message=AddLinearMoveRequest(
payload=AddLinearMoveRequestPayload(
group_id=UInt8Field(2),
seq_id=UInt8Field(1),
velocity=Int32Field(
int(
move_group_multiple[2][1][NodeId.pipette].velocity_mm_sec
move_group_multiple[2][1][NodeId.pipette_left].velocity_mm_sec
/ interrupts_per_sec
* (2 ** 31)
)
),
acceleration=Int32Field(0),
duration=UInt32Field(
int(
move_group_multiple[2][1][NodeId.pipette].duration_sec
move_group_multiple[2][1][NodeId.pipette_left].duration_sec
* interrupts_per_sec
)
),
Expand Down
6 changes: 3 additions & 3 deletions hardware/tests/test_scripts/test_can_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_prompt_message_without_payload(
) -> None:
"""It should create a message without payload."""
message_id = MessageId.get_status_request
node_id = NodeId.pipette
node_id = NodeId.pipette_left
mock_get_input.side_effect = [
str(list(MessageId).index(message_id)),
str(list(NodeId).index(node_id)),
Expand All @@ -57,7 +57,7 @@ def test_prompt_message_with_payload(
) -> None:
"""It should send a message with payload."""
message_id = MessageId.device_info_response
node_id = NodeId.pipette
node_id = NodeId.pipette_left
mock_get_input.side_effect = [
str(list(MessageId).index(message_id)),
str(list(NodeId).index(node_id)),
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_prompt_message_bad_input(
) -> None:
"""It should raise on bad input."""
message_id = MessageId.get_status_response
node_id = NodeId.pipette
node_id = NodeId.pipette_right
mock_get_input.side_effect = [
str(list(MessageId).index(message_id)),
str(list(NodeId).index(node_id)),
Expand Down