Skip to content

Commit 2ad804e

Browse files
committed
fixed calculation for labware height on modules
1 parent 62063ca commit 2ad804e

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

api/src/opentrons/protocol_engine/state/geometry.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def get_labware_parent_nominal_position(self, labware_id: str) -> Point:
136136
def _get_labware_position_offset(
137137
self, labware_id: str, labware_location: LabwareLocation
138138
) -> LabwareOffsetVector:
139-
"""Gets the offset vector of a labware on the given location."""
139+
"""Gets the offset vector of a labware on the given location.
140+
141+
NOTE: Not to be confused with LPC offset.
142+
"""
140143
if isinstance(labware_location, DeckSlotLocation):
141144
return LabwareOffsetVector(x=0, y=0, z=0)
142145
elif isinstance(labware_location, ModuleLocation):
@@ -434,17 +437,13 @@ def get_labware_grip_point(
434437
grip_height_from_labware_bottom = (
435438
self._labware.get_grip_height_from_labware_bottom(labware_id)
436439
)
437-
offset = LabwareOffsetVector(x=0, y=0, z=0)
438440
location_slot: DeckSlotName
439441

440-
if isinstance(location, ModuleLocation):
441-
deck_type = DeckType(self._labware.get_deck_definition()["otId"])
442-
offset = self._modules.get_module_offset(
443-
module_id=location.moduleId, deck_type=deck_type
444-
)
445-
location_slot = self._modules.get_location(location.moduleId).slotName
446-
elif isinstance(location, OnLabwareLocation):
447-
location_slot = self.get_ancestor_slot_name(location.labwareId)
442+
if isinstance(location, (ModuleLocation, OnLabwareLocation)):
443+
if isinstance(location, ModuleLocation):
444+
location_slot = self._modules.get_location(location.moduleId).slotName
445+
else:
446+
location_slot = self.get_ancestor_slot_name(location.labwareId)
448447
labware_offset = self._get_labware_position_offset(labware_id, location)
449448
# Get the calibrated offset if the on labware location is on top of a module, otherwise return empty one
450449
cal_offset = self._get_calibrated_module_offset(location)
@@ -455,6 +454,8 @@ def get_labware_grip_point(
455454
)
456455
else:
457456
location_slot = location.slotName
457+
offset = LabwareOffsetVector(x=0, y=0, z=0)
458+
458459
slot_center = self._labware.get_slot_center_position(location_slot)
459460
return Point(
460461
slot_center.x + offset.x,

api/tests/opentrons/protocol_engine/state/test_geometry_view.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,13 +1075,6 @@ def test_ensure_location_not_occupied_raises(
10751075
)
10761076

10771077

1078-
@pytest.mark.parametrize(
1079-
argnames=["location", "expected_center_point"],
1080-
argvalues=[
1081-
(DeckSlotLocation(slotName=DeckSlotName.SLOT_1), Point(101.0, 102.0, 203)),
1082-
(ModuleLocation(moduleId="module-id"), Point(111.0, 122.0, 233)),
1083-
],
1084-
)
10851078
def test_get_labware_grip_point(
10861079
decoy: Decoy,
10871080
labware_view: LabwareView,
@@ -1096,20 +1089,6 @@ def test_get_labware_grip_point(
10961089
labware_view.get_grip_height_from_labware_bottom("labware-id")
10971090
).then_return(100)
10981091

1099-
if isinstance(location, ModuleLocation):
1100-
decoy.when(labware_view.get_deck_definition()).then_return(
1101-
ot2_standard_deck_def
1102-
)
1103-
decoy.when(
1104-
module_view.get_module_offset(
1105-
module_id="module-id", deck_type=DeckType.OT2_STANDARD
1106-
)
1107-
).then_return(LabwareOffsetVector(x=10, y=20, z=30))
1108-
1109-
decoy.when(module_view.get_location("module-id")).then_return(
1110-
DeckSlotLocation(slotName=DeckSlotName.SLOT_1)
1111-
)
1112-
11131092
decoy.when(labware_view.get_slot_center_position(DeckSlotName.SLOT_1)).then_return(
11141093
Point(x=101, y=102, z=103)
11151094
)
@@ -1120,30 +1099,43 @@ def test_get_labware_grip_point(
11201099
assert labware_center == expected_center_point
11211100

11221101

1102+
@pytest.mark.parametrize(
1103+
argnames=["location", "expected_center_point"],
1104+
argvalues=[
1105+
(OnLabwareLocation(labwareId="labware-id"), Point(5, 10, 115.0)),
1106+
(ModuleLocation(moduleId="module-id"), Point(111.0, 122.0, 233)),
1107+
],
1108+
)
11231109
def test_get_labware_grip_point_on_labware(
11241110
decoy: Decoy,
11251111
labware_view: LabwareView,
11261112
module_view: ModuleView,
11271113
ot2_standard_deck_def: DeckDefinitionV3,
11281114
subject: GeometryView,
1115+
location: Union[ModuleLocation, OnLabwareLocation],
1116+
expected_center_point: Point,
11291117
) -> None:
11301118
"""It should get the grip point of a labware on another labware."""
1131-
decoy.when(labware_view.get(labware_id="labware-id")).then_return(
1132-
LoadedLabware(
1133-
id="labware-id",
1134-
loadName="above-name",
1135-
definitionUri="1234",
1136-
location=OnLabwareLocation(labwareId="below-id"),
1119+
if isinstance(location, ModuleLocation):
1120+
decoy.when(module_view.get_location("module-id")).then_return(DeckSlotLocation(slotName=DeckSlotName.SLOT_4))
1121+
else:
1122+
1123+
decoy.when(labware_view.get(labware_id="labware-id")).then_return(
1124+
LoadedLabware(
1125+
id="labware-id",
1126+
loadName="above-name",
1127+
definitionUri="1234",
1128+
location=OnLabwareLocation(labwareId="below-id"),
1129+
)
11371130
)
1138-
)
1139-
decoy.when(labware_view.get(labware_id="below-id")).then_return(
1140-
LoadedLabware(
1141-
id="below-id",
1142-
loadName="below-name",
1143-
definitionUri="1234",
1144-
location=DeckSlotLocation(slotName=DeckSlotName.SLOT_4),
1131+
decoy.when(labware_view.get(labware_id="below-id")).then_return(
1132+
LoadedLabware(
1133+
id="below-id",
1134+
loadName="below-name",
1135+
definitionUri="1234",
1136+
location=DeckSlotLocation(slotName=DeckSlotName.SLOT_4),
1137+
)
11451138
)
1146-
)
11471139

11481140
decoy.when(labware_view.get_dimensions("below-id")).then_return(
11491141
Dimensions(x=1000, y=1001, z=11)
@@ -1163,7 +1155,7 @@ def test_get_labware_grip_point_on_labware(
11631155
labware_id="labware-id", location=OnLabwareLocation(labwareId="below-id")
11641156
)
11651157

1166-
assert grip_point == Point(5, 10, 115.0)
1158+
assert grip_point == expected_center_point
11671159

11681160

11691161
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)