Skip to content

Commit

Permalink
wip: noodle around with location cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Apr 7, 2021
1 parent 247c5dc commit 2d9571b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/src/opentrons/protocols/api_support/definitions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .types import APIVersion

MAX_SUPPORTED_VERSION = APIVersion(2, 9)
MAX_SUPPORTED_VERSION = APIVersion(2, 10)
#: The maximum supported protocol API version in this release

V2_MODULE_DEF_VERSION = APIVersion(2, 3)
Expand Down
11 changes: 9 additions & 2 deletions api/src/opentrons/protocols/context/engine/protocol_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,15 @@ def get_rail_lights_on(self) -> bool:
def door_closed(self) -> bool:
raise NotImplementedError()

def get_last_location(self) -> Optional[types.Location]:
def get_last_location(
self,
mount: Optional[types.Mount] = None,
) -> Optional[types.Location]:
raise NotImplementedError()

def set_last_location(self, location: Optional[types.Location]) -> None:
def set_last_location(
self,
location: Optional[types.Location],
mount: Optional[types.Mount] = None,
) -> None:
raise NotImplementedError()
11 changes: 9 additions & 2 deletions api/src/opentrons/protocols/context/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ def door_closed(self) -> bool:
...

@abstractmethod
def get_last_location(self) -> Optional[types.Location]:
def get_last_location(
self,
mount: Optional[types.Mount] = None,
) -> Optional[types.Location]:
...

@abstractmethod
def set_last_location(self, location: Optional[types.Location]) -> None:
def set_last_location(
self,
location: Optional[types.Location],
mount: Optional[types.Mount] = None,
) -> None:
...
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ def move_to(self,
minimum_z_height: Optional[float],
speed: Optional[float]) -> None:
"""Move the instrument."""
last_location = self._protocol_interface.get_last_location()
# prevent direct movement bugs in PAPI version >= 2.10
location_cache_mount = (
self._mount
if self._api_version >= APIVersion(2, 10) else
None
)

last_location = self._protocol_interface.get_last_location(
mount=location_cache_mount
)

if last_location:
from_lw = last_location.labware
else:
Expand Down Expand Up @@ -190,7 +200,10 @@ def move_to(self,
self._protocol_interface.set_last_location(None)
raise
else:
self._protocol_interface.set_last_location(location)
self._protocol_interface.set_last_location(
location=location,
mount=location_cache_mount
)

def get_mount(self) -> types.Mount:
"""Get the mount this pipette is attached to."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(self,
self._bundled_data: Dict[str, bytes] = bundled_data or {}
self._default_max_speeds = AxisMaxSpeeds()
self._last_location: Optional[types.Location] = None
self._last_mount: Optional[types.Mount] = None
self._loaded_modules: Set['AbstractModule'] = set()

@classmethod
Expand Down Expand Up @@ -195,8 +196,8 @@ def load_module(
hc_mod_instance = None
for mod in available_modules:
compatible = module_geometry.models_compatible(
module_geometry.module_model_from_string(mod.model()),
resolved_model)
module_geometry.module_model_from_string(mod.model()),
resolved_model)
if compatible and mod not in self._loaded_modules:
self._loaded_modules.add(mod)
hc_mod_instance = SynchronousAdapter(mod)
Expand Down Expand Up @@ -295,10 +296,21 @@ def door_closed(self) -> bool:
"""Check if door is closed."""
return DoorState.CLOSED == self._hw_manager.hardware.door_state

def get_last_location(self) -> Optional[types.Location]:
def get_last_location(
self,
mount: Optional[types.Mount] = None,
) -> Optional[types.Location]:
"""Get the most recent moved to location."""
return self._last_location
if mount is None or mount == self._last_mount:
return self._last_location

def set_last_location(self, location: Optional[types.Location]) -> None:
return None

def set_last_location(
self,
location: Optional[types.Location],
mount: Optional[types.Mount] = None,
) -> None:
"""Set the most recent moved to location."""
self._last_location = location
self._last_mount = mount

0 comments on commit 2d9571b

Please sign in to comment.