Skip to content

Commit

Permalink
fix(engine): include modules w/o labware in motion planning (#10902)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Jun 24, 2022
1 parent 075179e commit 0b0dfae
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
9 changes: 7 additions & 2 deletions api/src/opentrons/protocol_engine/state/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ def get_labware_highest_z(self, labware_id: str) -> float:

return self._get_highest_z_from_labware_data(labware_data)

# TODO(mc, 2022-06-24): rename this method
def get_all_labware_highest_z(self) -> float:
"""Get the highest Z-point across all labware."""
return max(
[
*(
self._get_highest_z_from_labware_data(lw_data)
for lw_data in self._labware.get_all()
]
),
*(
self._modules.get_overall_height(module.id)
for module in self._modules.get_all()
),
)

def get_labware_parent_position(self, labware_id: str) -> Point:
Expand Down
2 changes: 0 additions & 2 deletions api/src/opentrons/protocol_engine/state/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,6 @@ def get_module_offset(self, module_id: str) -> LabwareOffsetVector:
z=definition.labwareOffset.z,
)

# TODO(mc, 2022-01-19): this method is missing unit test coverage and
# is also unused. Remove or add tests.
def get_overall_height(self, module_id: str) -> float:
"""Get the height of the module."""
return self.get_dimensions(module_id).bareOverallHeight
Expand Down
24 changes: 24 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DeckSlotLocation,
ModuleLocation,
LoadedLabware,
LoadedModule,
WellLocation,
WellOrigin,
WellOffset,
Expand Down Expand Up @@ -213,6 +214,7 @@ def test_get_all_labware_highest_z(
well_plate_def: LabwareDefinition,
reservoir_def: LabwareDefinition,
labware_view: LabwareView,
module_view: ModuleView,
subject: GeometryView,
) -> None:
"""It should get the highest Z amongst all labware."""
Expand All @@ -234,6 +236,8 @@ def test_get_all_labware_highest_z(
plate_offset = LabwareOffsetVector(x=1, y=-2, z=3)
reservoir_offset = LabwareOffsetVector(x=1, y=-2, z=3)

decoy.when(module_view.get_all()).then_return([])

decoy.when(labware_view.get_all()).then_return([plate, reservoir])
decoy.when(labware_view.get("plate-id")).then_return(plate)
decoy.when(labware_view.get("reservoir-id")).then_return(reservoir)
Expand Down Expand Up @@ -262,6 +266,26 @@ def test_get_all_labware_highest_z(
assert all_z == max(plate_z, reservoir_z)


def test_get_all_labware_highest_z_with_modules(
decoy: Decoy,
labware_view: LabwareView,
module_view: ModuleView,
subject: GeometryView,
) -> None:
"""It should get the highest Z including modules."""
module_1 = LoadedModule.construct(id="module-id-1") # type: ignore[call-arg]
module_2 = LoadedModule.construct(id="module-id-2") # type: ignore[call-arg]

decoy.when(labware_view.get_all()).then_return([])
decoy.when(module_view.get_all()).then_return([module_1, module_2])
decoy.when(module_view.get_overall_height("module-id-1")).then_return(42.0)
decoy.when(module_view.get_overall_height("module-id-2")).then_return(1337.0)

result = subject.get_all_labware_highest_z()

assert result == 1337.0


def test_get_labware_position(
decoy: Decoy,
well_plate_def: LabwareDefinition,
Expand Down
30 changes: 30 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_module_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,3 +1174,33 @@ def test_thermocycler_validate_target_lid_temperature_raises(

with pytest.raises(errors.InvalidTargetTemperatureError):
subject.validate_target_lid_temperature(input_temperature)


@pytest.mark.parametrize(
("module_definition", "expected_height"),
[
(lazy_fixture("thermocycler_v1_def"), 98.0),
(lazy_fixture("tempdeck_v1_def"), 84.0),
(lazy_fixture("tempdeck_v2_def"), 84.0),
(lazy_fixture("magdeck_v1_def"), 110.152),
(lazy_fixture("magdeck_v2_def"), 110.152),
(lazy_fixture("heater_shaker_v1_def"), 82.0),
],
)
def test_get_overall_height(
module_definition: ModuleDefinition,
expected_height: float,
) -> None:
"""It should get a module's overall height."""
subject = make_module_view(
slot_by_module_id={"module-id": DeckSlotName.SLOT_7},
hardware_by_module_id={
"module-id": HardwareModule(
serial_number="serial-number",
definition=module_definition,
)
},
)

result = subject.get_overall_height("module-id")
assert result == expected_height

0 comments on commit 0b0dfae

Please sign in to comment.