Skip to content

Commit 48f1134

Browse files
add xy offset to geometry
1 parent ddc149f commit 48f1134

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,40 @@ def validate_probed_height(
588588
f"Liquid Height of {probed_height} mm is greater than maximum well height {well_depth} mm."
589589
)
590590

591+
def get_xy_offset_if_needed(self, labware_id: str, well_name: str) -> WellOffset:
592+
"""Add an x,y offset to position the tip into the center of the well if needed."""
593+
well_def = self._labware.get_well_definition(labware_id, well_name)
594+
well_geometry = self._labware.get_well_geometry(
595+
labware_id=labware_id, well_name=well_name
596+
)
597+
x_offset = 0.0
598+
y_offset = 0.0
599+
if isinstance(well_geometry, InnerWellGeometry):
600+
sorted_well = sorted(
601+
well_geometry.sections, key=lambda section: section.topHeight
602+
)
603+
bottom_xcount = sorted_well[0].xCount
604+
bottom_ycount = sorted_well[0].yCount
605+
606+
if well_def.shape == "circular":
607+
well_x_dimension = well_y_dimension = well_def.diameter
608+
else:
609+
assert well_def.shape == "rectangular", "invalid well shape"
610+
well_x_dimension = well_def.xDimension
611+
well_y_dimension = well_def.yDimension
612+
613+
# if there are an even number of subsections, we'll need to reposition into
614+
# the middle of one of the subsections, rather than the middle of the whole well.
615+
if bottom_xcount % 2 == 0:
616+
subsection_x_dimension = well_x_dimension / bottom_xcount
617+
# move over into the middle of the nearest subsection
618+
x_offset = subsection_x_dimension / 2
619+
if bottom_ycount % 2 == 0:
620+
subsection_y_dimension = well_y_dimension / bottom_ycount
621+
# move over into the middle of the nearest subection
622+
y_offset = subsection_y_dimension / 2
623+
return WellOffset(x=x_offset, y=y_offset, z=0)
624+
591625
def get_well_position(
592626
self,
593627
labware_id: str,
@@ -600,8 +634,10 @@ def get_well_position(
600634
labware_pos = self.get_labware_position(labware_id)
601635
well_def = self._labware.get_well_definition(labware_id, well_name)
602636
well_depth = well_def.depth
603-
604-
offset = WellOffset(x=0, y=0, z=well_depth)
637+
xy_offset = self.get_xy_offset_if_needed(
638+
labware_id=labware_id, well_name=well_name
639+
)
640+
offset = WellOffset(x=xy_offset.x, y=xy_offset.y, z=well_depth)
605641
if well_location is not None:
606642
offset = well_location.offset # location of the bottom of the well
607643
offset_adjustment = self.get_well_offset_adjustment(

0 commit comments

Comments
 (0)