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

feat(api): change liquid_probe to respect min well height #15488

Merged
merged 12 commits into from
Jun 26, 2024
1 change: 1 addition & 0 deletions api/src/opentrons/hardware_control/dev_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class PipetteDict(InstrumentDict):
supported_tips: Dict[PipetteTipType, SupportedTipsDefinition]
pipette_bounding_box_offsets: PipetteBoundingBoxOffsetDefinition
current_nozzle_map: NozzleMap
lld_settings: Optional[Dict[str, Dict[str, float]]]


class PipetteStateDict(TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def get_attached_instrument(self, mount: MountType) -> PipetteDict:
"default_dispense_flow_rates",
"back_compat_names",
"supported_tips",
"lld_settings",
]

instr_dict = instr.as_dict()
Expand Down Expand Up @@ -258,6 +259,7 @@ def get_attached_instrument(self, mount: MountType) -> PipetteDict:
result[
"pipette_bounding_box_offsets"
] = instr.config.pipette_bounding_box_offsets
result["lld_settings"] = instr.config.lld_settings
return cast(PipetteDict, result)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def get_attached_instrument(self, mount: OT3Mount) -> PipetteDict:
"default_dispense_flow_rates",
"back_compat_names",
"supported_tips",
"lld_settings",
]

instr_dict = instr.as_dict()
Expand Down Expand Up @@ -279,6 +280,7 @@ def get_attached_instrument(self, mount: OT3Mount) -> PipetteDict:
result[
"pipette_bounding_box_offsets"
] = instr.config.pipette_bounding_box_offsets
result["lld_settings"] = instr.config.lld_settings
return cast(PipetteDict, result)

@property
Expand Down
5 changes: 4 additions & 1 deletion api/src/opentrons/protocol_engine/execution/pipetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ async def liquid_probe_in_place(
)
well_def = self._state_view.labware.get_well_definition(labware_id, well_name)
well_depth = well_def.depth
lld_min_height = self._state_view.pipettes.get_current_tip_lld_settings(
pipette_id=pipette_id
)
z_pos = await self._hardware_api.liquid_probe(
mount=hw_pipette.mount, max_z_dist=well_depth
mount=hw_pipette.mount, max_z_dist=well_depth - lld_min_height
)
return float(z_pos)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class LoadedStaticPipetteData:
nozzle_map: NozzleMap
back_left_corner_offset: Point
front_right_corner_offset: Point
pipette_lld_settings: Optional[Dict[str, Dict[str, float]]]


class VirtualPipetteDataProvider:
Expand Down Expand Up @@ -240,6 +241,7 @@ def _get_virtual_pipette_static_config_by_model( # noqa: C901
front_right_corner_offset=Point(
pip_front_right[0], pip_front_right[1], pip_front_right[2]
),
pipette_lld_settings=config.lld_settings,
)

def get_virtual_pipette_static_config(
Expand Down Expand Up @@ -282,4 +284,5 @@ def get_pipette_static_config(pipette_dict: PipetteDict) -> LoadedStaticPipetteD
front_right_corner_offset=Point(
front_right_offset[0], front_right_offset[1], front_right_offset[2]
),
pipette_lld_settings=pipette_dict["lld_settings"],
)
23 changes: 23 additions & 0 deletions api/src/opentrons/protocol_engine/state/pipettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class StaticPipetteConfig:
pipette_bounding_box_offsets: PipetteBoundingBoxOffsets
bounding_nozzle_offsets: BoundingNozzlesOffsets
default_nozzle_map: NozzleMap
lld_settings: Optional[Dict[str, Dict[str, float]]]


@dataclass
Expand Down Expand Up @@ -197,6 +198,7 @@ def _handle_command( # noqa: C901
front_right_offset=config.nozzle_map.front_right_nozzle_offset,
),
default_nozzle_map=config.nozzle_map,
lld_settings=config.pipette_lld_settings,
)
self._state.flow_rates_by_id[private_result.pipette_id] = config.flow_rates
self._state.nozzle_configuration_by_id[
Expand Down Expand Up @@ -618,6 +620,27 @@ def get_available_volume(self, pipette_id: str) -> Optional[float]:

return max(0.0, working_volume - current_volume) if current_volume else None

def get_pipette_lld_settings(
self, pipette_id: str
) -> Optional[Dict[str, Dict[str, float]]]:
"""Get the liquid level settings for all possible tips for a single pipette."""
return self.get_config(pipette_id).lld_settings

def get_current_tip_lld_settings(self, pipette_id: str) -> float:
"""Get the liquid level settings for pipette and its current tip."""
attached_tip = self.get_attached_tip(pipette_id)
if attached_tip is None or attached_tip.volume is None:
return 0
lld_settings = self.get_pipette_lld_settings(pipette_id)
tipVolume = str(attached_tip.volume)
if (
lld_settings is None
or lld_settings[tipVolume] is None
or lld_settings[tipVolume]["minHeight"] is None
):
return 0
return float(lld_settings[tipVolume]["minHeight"])

def validate_tip_state(self, pipette_id: str, expected_has_tip: bool) -> None:
"""Validate that a pipette's tip state matches expectations."""
attached_tip = self.get_attached_tip(pipette_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def test_configure_for_volume_implementation(
nozzle_map=get_default_nozzle_map(PipetteNameType.P300_MULTI),
back_left_corner_offset=Point(10, 20, 30),
front_right_corner_offset=Point(40, 50, 60),
pipette_lld_settings={},
)

decoy.when(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def test_load_pipette_implementation(
nozzle_map=get_default_nozzle_map(PipetteNameType.P300_MULTI),
back_left_corner_offset=Point(x=1, y=2, z=3),
front_right_corner_offset=Point(x=4, y=5, z=6),
pipette_lld_settings={},
)
data = LoadPipetteParams(
pipetteName=PipetteNameType.P300_SINGLE,
Expand Down Expand Up @@ -106,6 +107,7 @@ async def test_load_pipette_implementation_96_channel(
nozzle_map=get_default_nozzle_map(PipetteNameType.P1000_96),
back_left_corner_offset=Point(x=1, y=2, z=3),
front_right_corner_offset=Point(x=4, y=5, z=6),
pipette_lld_settings={},
)

decoy.when(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def loaded_static_pipette_data(
nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
back_left_corner_offset=Point(x=1, y=2, z=3),
front_right_corner_offset=Point(x=4, y=5, z=6),
pipette_lld_settings={},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_get_virtual_pipette_static_config(
nozzle_map=result.nozzle_map,
back_left_corner_offset=Point(0, 0, 10.45),
front_right_corner_offset=Point(0, 0, 10.45),
pipette_lld_settings={},
)


Expand Down Expand Up @@ -86,6 +87,7 @@ def test_configure_virtual_pipette_for_volume(
nozzle_map=result1.nozzle_map,
back_left_corner_offset=Point(-8.0, -22.0, -259.15),
front_right_corner_offset=Point(-8.0, -22.0, -259.15),
pipette_lld_settings={"t50": {"minHeight": 0.5, "minVolume": 0.0}},
)
subject_instance.configure_virtual_pipette_for_volume(
"my-pipette", 1, result1.model
Expand All @@ -111,6 +113,7 @@ def test_configure_virtual_pipette_for_volume(
nozzle_map=result2.nozzle_map,
back_left_corner_offset=Point(-8.0, -22.0, -259.15),
front_right_corner_offset=Point(-8.0, -22.0, -259.15),
pipette_lld_settings={"t50": {"minHeight": 0.5, "minVolume": 0.0}},
)


Expand Down Expand Up @@ -139,6 +142,7 @@ def test_load_virtual_pipette_by_model_string(
nozzle_map=result.nozzle_map,
back_left_corner_offset=Point(-16.0, 43.15, 35.52),
front_right_corner_offset=Point(16.0, -43.15, 35.52),
pipette_lld_settings={},
)


Expand Down Expand Up @@ -225,6 +229,11 @@ def test_get_pipette_static_config(
backLeftCorner=[10, 20, 30],
frontRightCorner=[40, 50, 60],
),
"lld_settings": {
"t50": {"minHeight": 0.5, "minVolume": 0},
"t200": {"minHeight": 0.5, "minVolume": 0},
"t1000": {"minHeight": 0.5, "minVolume": 0},
},
}

result = subject.get_pipette_static_config(pipette_dict)
Expand Down Expand Up @@ -253,4 +262,9 @@ def test_get_pipette_static_config(
nozzle_map=dummy_nozzle_map,
back_left_corner_offset=Point(10, 20, 30),
front_right_corner_offset=Point(40, 50, 60),
pipette_lld_settings={
"t50": {"minHeight": 0.5, "minVolume": 0},
"t200": {"minHeight": 0.5, "minVolume": 0},
"t1000": {"minHeight": 0.5, "minVolume": 0},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,7 @@ def test_get_next_drop_tip_location(
back_left_corner=Point(x=10, y=20, z=30),
front_right_corner=Point(x=40, y=50, z=60),
),
lld_settings={},
)
)
decoy.when(mock_pipette_view.get_mount("pip-123")).then_return(pipette_mount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ def test_add_pipette_config(
nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
back_left_corner_offset=Point(x=1, y=2, z=3),
front_right_corner_offset=Point(x=4, y=5, z=6),
pipette_lld_settings={},
),
)
subject.handle_action(
Expand All @@ -774,6 +775,7 @@ def test_add_pipette_config(
back_left_corner=Point(x=1, y=2, z=3),
front_right_corner=Point(x=4, y=5, z=6),
),
lld_settings={},
)
assert subject.state.flow_rates_by_id["pipette-id"].default_aspirate == {"a": 1.0}
assert subject.state.flow_rates_by_id["pipette-id"].default_dispense == {"b": 2.0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def test_get_pipette_working_volume(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
)
},
)
Expand Down Expand Up @@ -306,6 +307,7 @@ def test_get_pipette_working_volume_raises_if_tip_volume_is_none(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
)
},
)
Expand Down Expand Up @@ -345,6 +347,7 @@ def test_get_pipette_available_volume(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
),
"pipette-id-none": StaticPipetteConfig(
min_volume=1,
Expand All @@ -360,6 +363,7 @@ def test_get_pipette_available_volume(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
),
},
)
Expand Down Expand Up @@ -471,6 +475,7 @@ def test_get_static_config(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
)

subject = get_pipette_view(
Expand Down Expand Up @@ -521,6 +526,7 @@ def test_get_nominal_tip_overlap(
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
pipette_bounding_box_offsets=_SAMPLE_PIPETTE_BOUNDING_BOX_OFFSETS,
lld_settings={},
)

subject = get_pipette_view(static_config_by_id={"pipette-id": config})
Expand Down Expand Up @@ -781,6 +787,7 @@ def test_get_nozzle_bounds_at_location(
default_nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE),
bounding_nozzle_offsets=_SAMPLE_NOZZLE_BOUNDS_OFFSETS,
pipette_bounding_box_offsets=bounding_box_offsets,
lld_settings={},
)
},
)
Expand Down
Loading
Loading