-
Notifications
You must be signed in to change notification settings - Fork 178
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
refactor(api): hardware controller use error codes #13318
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
cast, | ||
) | ||
|
||
from opentrons_shared_data.errors.exceptions import ( | ||
PositionUnknownError, | ||
UnsupportedHardwareCommand, | ||
) | ||
from opentrons_shared_data.pipette import ( | ||
pipette_load_name_conversions as pipette_load_name, | ||
) | ||
|
@@ -54,10 +58,6 @@ | |
SubSystem, | ||
SubSystemState, | ||
) | ||
from .errors import ( | ||
MustHomeError, | ||
NotSupportedByHardware, | ||
) | ||
from . import modules | ||
from .robot_calibration import ( | ||
RobotCalibrationProvider, | ||
|
@@ -602,8 +602,8 @@ async def home(self, axes: Optional[List[Axis]] = None) -> None: | |
# can still explicitly specify an OT3 axis even when working on an OT2. | ||
# Adding this check in order to prevent misuse of axes types. | ||
if axes and any(axis not in Axis.ot2_axes() for axis in axes): | ||
raise NotSupportedByHardware( | ||
f"At least one axis in {axes} is not supported on the OT2." | ||
raise UnsupportedHardwareCommand( | ||
message=f"At least one axis in {axes} is not supported on the OT2." | ||
) | ||
self._reset_last_mount() | ||
# Initialize/update current_position | ||
|
@@ -645,12 +645,14 @@ async def current_position( | |
not self._backend.is_homed([ot2_axis_to_string(a) for a in position_axes]) | ||
or not self._current_position | ||
): | ||
raise MustHomeError( | ||
f"Current position of {str(mount)} pipette is unknown, please home." | ||
raise PositionUnknownError( | ||
message=f"Current position of {str(mount)} pipette is unknown, please home." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe put in the details whether the problem is that the axis isn't homed or that position hasn't been pulled yet |
||
) | ||
|
||
elif not self._current_position and not refresh: | ||
raise MustHomeError("Current position is unknown; please home motors.") | ||
raise PositionUnknownError( | ||
message="Current position is unknown; please home motors." | ||
) | ||
async with self._motion_lock: | ||
if refresh: | ||
smoothie_pos = await self._backend.update_position() | ||
|
@@ -730,7 +732,9 @@ async def move_axes( | |
The effector of the x,y axis is the center of the carriage. | ||
The effector of the pipette mount axis are the mount critical points but only in z. | ||
""" | ||
raise NotSupportedByHardware("move_axes is not supported on the OT-2.") | ||
raise UnsupportedHardwareCommand( | ||
message="move_axes is not supported on the OT-2." | ||
) | ||
|
||
async def move_rel( | ||
self, | ||
|
@@ -748,8 +752,8 @@ async def move_rel( | |
# TODO: Remove the fail_on_not_homed and make this the behavior all the time. | ||
# Having the optional arg makes the bug stick around in existing code and we | ||
# really want to fix it when we're not gearing up for a release. | ||
mhe = MustHomeError( | ||
"Cannot make a relative move because absolute position is unknown" | ||
mhe = PositionUnknownError( | ||
message="Cannot make a relative move because absolute position is unknown" | ||
) | ||
if not self._current_position: | ||
if fail_on_not_homed: | ||
|
@@ -937,7 +941,7 @@ async def prepare_for_aspirate( | |
Prepare the pipette for aspiration. | ||
""" | ||
instrument = self.get_pipette(mount) | ||
self.ready_for_tip_action(instrument, HardwareAction.PREPARE_ASPIRATE) | ||
self.ready_for_tip_action(instrument, HardwareAction.PREPARE_ASPIRATE, mount) | ||
|
||
if instrument.current_volume == 0: | ||
speed = self.plunger_speed( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,43 @@ | ||
from opentrons_shared_data.errors.exceptions import PipetteOverpressureError | ||
from .types import OT3Mount | ||
from typing import Optional, Dict, Any | ||
from opentrons_shared_data.errors.exceptions import ( | ||
MotionPlanningFailureError, | ||
InvalidInstrumentData, | ||
RobotInUseError, | ||
) | ||
|
||
|
||
class OutOfBoundsMove(RuntimeError): | ||
def __init__(self, message: str): | ||
self.message = message | ||
super().__init__() | ||
class OutOfBoundsMove(MotionPlanningFailureError): | ||
def __init__(self, message: str, detail: Dict[str, Any]): | ||
super().__init__(message=message, detail=detail) | ||
|
||
def __str__(self) -> str: | ||
return f"OutOfBoundsMove: {self.message}" | ||
|
||
def __repr__(self) -> str: | ||
return f"<{str(self.__class__)}: {self.message}>" | ||
|
||
|
||
class ExecutionCancelledError(RuntimeError): | ||
pass | ||
|
||
|
||
class MustHomeError(RuntimeError): | ||
pass | ||
|
||
|
||
class NoTipAttachedError(RuntimeError): | ||
pass | ||
|
||
|
||
class TipAttachedError(RuntimeError): | ||
pass | ||
|
||
|
||
class InvalidMoveError(ValueError): | ||
pass | ||
|
||
|
||
class NotSupportedByHardware(ValueError): | ||
"""Error raised when attempting to use arguments and values not supported by the specific hardware.""" | ||
|
||
|
||
class GripperNotAttachedError(Exception): | ||
"""An error raised if a gripper is accessed that is not attached.""" | ||
|
||
pass | ||
|
||
|
||
class AxisNotPresentError(Exception): | ||
"""An error raised if an axis that is not present.""" | ||
|
||
pass | ||
|
||
|
||
class FirmwareUpdateRequired(RuntimeError): | ||
"""An error raised when the firmware of the submodules needs to be updated.""" | ||
|
||
pass | ||
|
||
|
||
class FirmwareUpdateFailed(RuntimeError): | ||
"""An error raised when a firmware update fails.""" | ||
|
||
pass | ||
|
||
|
||
class OverPressureDetected(PipetteOverpressureError): | ||
"""An error raised when the pressure sensor max value is exceeded.""" | ||
|
||
def __init__(self, mount: str) -> None: | ||
return super().__init__( | ||
message=f"The pressure sensor on the {mount} mount has exceeded operational limits.", | ||
detail={"mount": mount}, | ||
class InvalidCriticalPoint(MotionPlanningFailureError): | ||
def __init__(self, cp_name: str, instr: str, message: Optional[str] = None): | ||
super().__init__( | ||
message=(message or f"Critical point {cp_name} is invalid for a {instr}."), | ||
detail={"instrument": instr, "critical point": cp_name}, | ||
) | ||
|
||
|
||
class InvalidPipetteName(KeyError): | ||
class InvalidPipetteName(InvalidInstrumentData): | ||
"""Raised for an invalid pipette.""" | ||
|
||
def __init__(self, name: int, mount: OT3Mount) -> None: | ||
self.name = name | ||
self.mount = mount | ||
|
||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}: name={self.name} mount={self.mount}>" | ||
|
||
def __str__(self) -> str: | ||
return f"{self.__class__.__name__}: Pipette name key {self.name} on mount {self.mount.name} is not valid" | ||
def __init__(self, name: int, mount: str) -> None: | ||
super().__init__( | ||
message=f"Invalid pipette name key {name} on mount {mount}", | ||
detail={"mount": mount, "name": name}, | ||
) | ||
|
||
|
||
class InvalidPipetteModel(KeyError): | ||
class InvalidPipetteModel(InvalidInstrumentData): | ||
"""Raised for a pipette with an unknown model.""" | ||
|
||
def __init__(self, name: str, model: str, mount: OT3Mount) -> None: | ||
self.name = name | ||
self.model = model | ||
self.mount = mount | ||
def __init__(self, name: str, model: str, mount: str) -> None: | ||
super().__init__(detail={"mount": mount, "name": name, "model": model}) | ||
|
||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}: name={self.name}, model={self.model}, mount={self.mount}>" | ||
|
||
def __str__(self) -> str: | ||
return f"{self.__class__.__name__}: {self.name} on {self.mount.name} has an unknown model {self.model}" | ||
|
||
|
||
class UpdateOngoingError(RuntimeError): | ||
class UpdateOngoingError(RobotInUseError): | ||
"""Error when an update is already happening.""" | ||
|
||
def __init__(self, msg: str) -> None: | ||
self.msg = msg | ||
|
||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}: msg={self.msg}>" | ||
|
||
def __str__(self) -> str: | ||
return self.msg | ||
def __init__(self, message: str) -> None: | ||
super().__init__(message=message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe worth putting in which axis it is, at least in the details