Skip to content

Commit

Permalink
fix cache instrument motion lock
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Mar 4, 2024
1 parent ce83df3 commit 99db5ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ async def watch(self, loop: asyncio.AbstractEventLoop) -> None:
def axis_bounds(self) -> OT3AxisMap[Tuple[float, float]]:
"""Get the axis bounds."""
# TODO (AL, 2021-11-18): The bounds need to be defined
phony_bounds = (0, 10000)
phony_bounds = (0, 500)
return {
Axis.Z_L: phony_bounds,
Axis.Z_R: phony_bounds,
Expand Down
27 changes: 15 additions & 12 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,11 @@ async def cache_instruments(
Scan the attached instruments, take necessary configuration actions,
and set up hardware controller internal state if necessary.
"""
skip_configure = await self._cache_instruments(require)
if not skip_configure or not self._configured_since_update:
self._log.info("Reconfiguring instrument cache")
await self._configure_instruments()
async with self._motion_lock:
skip_configure = await self._cache_instruments(require)
if not skip_configure or not self._configured_since_update:
self._log.info("Reconfiguring instrument cache")
await self._configure_instruments()

async def _cache_instruments( # noqa: C901
self, require: Optional[Dict[top_types.Mount, PipetteName]] = None
Expand All @@ -676,11 +677,11 @@ async def _cache_instruments( # noqa: C901
# We should also check version here once we're comfortable.
if not pipette_load_name.supported_pipette(name):
raise RuntimeError(f"{name} is not a valid pipette name")
async with self._motion_lock:
# we're not actually checking the required instrument except in the context
# of simulation and it feels like a lot of work for this function
# actually be doing.
found = await self._backend.get_attached_instruments(checked_require)

# we're not actually checking the required instrument except in the context
# of simulation and it feels like a lot of work for this function
# actually be doing.
found = await self._backend.get_attached_instruments(checked_require)

if OT3Mount.GRIPPER in found.keys():
# Is now a gripper, ask if it's ok to skip
Expand Down Expand Up @@ -726,7 +727,7 @@ async def _cache_instruments( # noqa: C901
async def _configure_instruments(self) -> None:
"""Configure instruments"""
await self.set_gantry_load(self._gantry_load_from_instruments())
await self.refresh_positions()
await self.refresh_positions(acquire_lock=False)
await self.reset_tip_detectors(False)
self._configured_since_update = True

Expand Down Expand Up @@ -983,9 +984,11 @@ async def current_position_ot3(
OT3Mount.from_mount(mount), self._current_position, critical_point
)

async def refresh_positions(self) -> None:
async def refresh_positions(self, acquire_lock: bool = True) -> None:
"""Request and update both the motor and encoder positions from backend."""
async with self._motion_lock:
async with contextlib.AsyncExitStack() as stack:
if acquire_lock:
await stack.enter_async_context(self._motion_lock)
await self._backend.update_motor_status()
await self._cache_current_position()
await self._cache_encoder_position()
Expand Down

0 comments on commit 99db5ec

Please sign in to comment.