-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'edge' into app_fix-robot-rename-regex
- Loading branch information
Showing
33 changed files
with
1,001 additions
and
360 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
import logging | ||
from typing import Tuple | ||
from typing_extensions import Literal | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
GripperName = Literal["gripper"] | ||
GripperModel = Literal["gripper_v1"] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class GripperConfig: | ||
gripper_offset: Tuple[float, float, float] | ||
gripper_current: float | ||
display_name: str | ||
name: GripperName | ||
max_travel: float | ||
home_position: float | ||
steps_per_mm: float | ||
idle_current: float | ||
model: GripperModel |
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
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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from __future__ import annotations | ||
|
||
""" Classes and functions for gripper state tracking | ||
""" | ||
from dataclasses import asdict, replace | ||
import logging | ||
from typing import Any, Dict, Optional, Union | ||
|
||
from opentrons.types import Point | ||
from opentrons.config import gripper_config | ||
from .instrument_abc import AbstractInstrument | ||
from .types import CriticalPoint | ||
|
||
RECONFIG_KEYS = {"quirks"} | ||
|
||
|
||
mod_log = logging.getLogger(__name__) | ||
|
||
|
||
class Gripper(AbstractInstrument[gripper_config.GripperConfig]): | ||
"""A class to gather and track gripper state and configs. | ||
This class should not touch hardware or call back out to the hardware | ||
control API. Its only purpose is to gather state. | ||
""" | ||
|
||
DictType = Dict[str, Union[str, float, bool]] | ||
#: The type of this data class as a dict | ||
|
||
def __init__( | ||
self, | ||
config: gripper_config.GripperConfig, | ||
gripper_id: Optional[str] = None, | ||
) -> None: | ||
self._config = config | ||
self._name = self._config.name | ||
self._model = self._config.model | ||
self._gripper_id = gripper_id | ||
self._log = mod_log.getChild( | ||
self._gripper_id if self._gripper_id else "<unknown>" | ||
) | ||
# cache a dict representation of config for improved performance of | ||
# as_dict. | ||
self._config_as_dict = asdict(config) | ||
|
||
@property | ||
def config(self) -> gripper_config.GripperConfig: | ||
return self._config | ||
|
||
def update_config_item(self, elem_name: str, elem_val: Any) -> None: | ||
self._log.info(f"updated config: {elem_name}={elem_val}") | ||
self._config = replace(self._config, **{elem_name: elem_val}) | ||
# Update the cached dict representation | ||
self._config_as_dict = asdict(self._config) | ||
|
||
@property | ||
def name(self) -> gripper_config.GripperName: | ||
return self._name | ||
|
||
@property | ||
def model(self) -> gripper_config.GripperModel: | ||
return self._model | ||
|
||
@property | ||
def gripper_id(self) -> Optional[str]: | ||
return self._gripper_id | ||
|
||
def critical_point(self, cp_override: Optional[CriticalPoint] = None) -> Point: | ||
""" | ||
The vector from the gripper's origin to its critical point. The | ||
critical point for a pipette is the end of the nozzle if no tip is | ||
attached, or the end of the tip if a tip is attached. | ||
""" | ||
# TODO: add critical point implementation | ||
return Point(0, 0, 0) | ||
|
||
def __str__(self) -> str: | ||
return f"{self._config.display_name}" | ||
|
||
def __repr__(self) -> str: | ||
return f"<{self.__class__.__name__}: {self._config.display_name} {id(self)}" | ||
|
||
def as_dict(self) -> "Gripper.DictType": | ||
self._config_as_dict.update( | ||
{ | ||
"name": self.name, | ||
"model": self.model, | ||
"gripper_id": self.gripper_id, | ||
} | ||
) | ||
return self._config_as_dict |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Optional, Generic, TypeVar | ||
|
||
from opentrons.types import Point | ||
from .types import CriticalPoint | ||
|
||
|
||
InstrumentConfig = TypeVar("InstrumentConfig") | ||
|
||
|
||
class AbstractInstrument(ABC, Generic[InstrumentConfig]): | ||
"""Defines the common methods of an instrument.""" | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Return name of the instrument.""" | ||
... | ||
|
||
@property | ||
def model(self) -> str: | ||
"""Return model of the instrument.""" | ||
... | ||
|
||
@property | ||
def config(self) -> InstrumentConfig: | ||
"""Instrument config in dataclass format.""" | ||
... | ||
|
||
@abstractmethod | ||
def update_config_item(self, elem_name: str, elem_val: Any) -> None: | ||
"""Update instrument config item.""" | ||
... | ||
|
||
@abstractmethod | ||
def critical_point(self, cp_override: Optional[CriticalPoint] = None) -> Point: | ||
"""Computate critical point of an instrument.""" | ||
... |
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.