Skip to content

Commit

Permalink
feat(hardware control): create logic to detect if tip has hit bottom … (
Browse files Browse the repository at this point in the history
#15389)

…of well or liquid

Creates a new file called sensor_utils.py. Introduces new error type for
tip hitting bottom of the well when searching for liquid. Creates a
function that detects whether the tip has hit a liquid or the bottom of
the well based on pressure data.

fix EXEC-517

<!--
Thanks for taking the time to open a pull request! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

<!--
Use this section to describe your pull-request at a high level. If the
PR addresses any open issues, please tag the issues here.
-->

# Test Plan

<!--
Use this section to describe the steps that you took to test your Pull
Request.
If you did not perform any testing provide justification why.

OT-3 Developers: You should default to testing on actual physical
hardware.
Once again, if you did not perform testing against hardware, justify
why.

Note: It can be helpful to write a test plan before doing development

Example Test Plan (HTTP API Change)

- Verified that new optional argument `dance-party` causes the robot to
flash its lights, move the pipettes,
then home.
- Verified that when you omit the `dance-party` option the robot homes
normally
- Added protocol that uses `dance-party` argument to G-Code Testing
Suite
- Ran protocol that did not use `dance-party` argument and everything
was successful
- Added unit tests to validate that changes to pydantic model are
correct

-->

# Changelog

<!--
List out the changes to the code in this PR. Please try your best to
categorize your changes and describe what has changed and why.

Example changelog:
- Fixed app crash when trying to calibrate an illegal pipette
- Added state to API to track pipette usage
- Updated API docs to mention only two pipettes are supported

IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED
-->

# Review requests

<!--
Describe any requests for your reviewers here.
-->

# Risk assessment

<!--
Carefully go over your pull request and look at the other parts of the
codebase it may affect. Look for the possibility, even if you think it's
small, that your change may affect some other part of the system - for
instance, changing return tip behavior in protocol may also change the
behavior of labware calibration.

Identify the other parts of the system your codebase may affect, so that
in addition to your own review and testing, other people who may not
have the system internalized as much as you can focus their attention
and testing there.
-->
  • Loading branch information
aaron-kulkarni authored Jun 13, 2024
1 parent 4d13152 commit 5ce130b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hardware/opentrons_hardware/hardware_control/sensor_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Functions aiding in Liquid Level Detection."""

from opentrons_shared_data.errors.exceptions import (
TipHitWellBottomError,
LiquidNotFoundError,
)


import numpy as np


def did_tip_hit_liquid(
pressure_readings: list[float], liquid_solid_threshold: float
) -> bool:
"""Detects if tip has hit liquid or solid based on given pressure data."""
if len(pressure_readings) < 5:
raise LiquidNotFoundError(
"Liquid not found. Not enough data to calculate pressure change",
)
pressure_difference = np.gradient(pressure_readings[-5:], 1)
end_difference = pressure_difference[-1]
if end_difference > liquid_solid_threshold:
# Hit Bottom of Well
raise TipHitWellBottomError(
"Tip hit the bottom of the well.",
{"Pressure change detected: ": str(end_difference)},
)
else:
# Hit Liquid
return True
4 changes: 4 additions & 0 deletions shared-data/errors/definitions/1/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
"detail": "Liquid Not Found",
"category": "roboticsControlError"
},
"2018": {
"detail": "Tip Hit Well Bottom",
"category": "roboticsControlError"
},
"3000": {
"detail": "A robotics interaction error occurred.",
"category": "roboticsInteractionError"
Expand Down
1 change: 1 addition & 0 deletions shared-data/python/opentrons_shared_data/errors/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ErrorCodes(Enum):
FAILED_GRIPPER_PICKUP_ERROR = _code_from_dict_entry("2015")
MOTOR_DRIVER_ERROR = _code_from_dict_entry("2016")
LIQUID_NOT_FOUND = _code_from_dict_entry("2017")
TIP_HIT_WELL_BOTTOM = _code_from_dict_entry("2018")
ROBOTICS_INTERACTION_ERROR = _code_from_dict_entry("3000")
LABWARE_DROPPED = _code_from_dict_entry("3001")
LABWARE_NOT_PICKED_UP = _code_from_dict_entry("3002")
Expand Down
18 changes: 18 additions & 0 deletions shared-data/python/opentrons_shared_data/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ def __init__(
)


class TipHitWellBottomError(RoboticsControlError):
"""Error raised if tip hits bottom of well while trying to detect liquid level."""

def __init__(
self,
message: Optional[str] = None,
detail: Optional[Dict[str, str]] = None,
wrapping: Optional[Sequence[EnumeratedError]] = None,
) -> None:
"""Initialize TipHitWellBottomError."""
super().__init__(
ErrorCodes.TIP_HIT_WELL_BOTTOM,
message,
detail,
wrapping,
)


class LabwareDroppedError(RoboticsInteractionError):
"""An error indicating that the gripper dropped labware it was holding."""

Expand Down

0 comments on commit 5ce130b

Please sign in to comment.