Skip to content

Commit

Permalink
pass through response queue option
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Oct 10, 2024
1 parent bff9cc3 commit 59abe33
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
5 changes: 5 additions & 0 deletions api/src/opentrons/hardware_control/backends/flex_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
StatusBarState,
)
from opentrons.hardware_control.module_control import AttachedModulesControl
from opentrons_hardware.firmware_bindings.constants import SensorId
from opentrons_hardware.sensors.types import SensorDataType
from ..dev_types import OT3AttachedInstruments
from .types import HWStopCondition

Expand Down Expand Up @@ -154,6 +156,9 @@ async def liquid_probe(
num_baseline_reads: int,
probe: InstrumentProbeType = InstrumentProbeType.PRIMARY,
force_both_sensors: bool = False,
response_queue: Optional[
asyncio.Queue[dict[SensorId, list[SensorDataType]]]
] = None,
) -> float:
...

Expand Down
6 changes: 6 additions & 0 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
NodeId,
PipetteName as FirmwarePipetteName,
ErrorCode,
SensorId,
)
from opentrons_hardware.sensors.types import SensorDataType
from opentrons_hardware.firmware_bindings.messages.message_definitions import (
StopRequest,
)
Expand Down Expand Up @@ -1370,6 +1372,9 @@ async def liquid_probe(
num_baseline_reads: int,
probe: InstrumentProbeType = InstrumentProbeType.PRIMARY,
force_both_sensors: bool = False,
response_queue: Optional[
asyncio.Queue[dict[SensorId, list[SensorDataType]]]
] = None,
) -> float:
head_node = axis_to_node(Axis.by_mount(mount))
tool = sensor_node_for_pipette(OT3Mount(mount.value))
Expand All @@ -1385,6 +1390,7 @@ async def liquid_probe(
num_baseline_reads=num_baseline_reads,
sensor_id=sensor_id_for_instrument(probe),
force_both_sensors=force_both_sensors,
response_queue=response_queue,
)
for node, point in positions.items():
self._position.update({node: point.motor_position})
Expand Down
6 changes: 5 additions & 1 deletion api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
from opentrons.util.async_helpers import ensure_yield
from .types import HWStopCondition
from .flex_protocol import FlexBackend

from opentrons_hardware.firmware_bindings.constants import SensorId
from opentrons_hardware.sensors.types import SensorDataType

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -349,6 +350,9 @@ async def liquid_probe(
num_baseline_reads: int,
probe: InstrumentProbeType = InstrumentProbeType.PRIMARY,
force_both_sensors: bool = False,
response_queue: Optional[
asyncio.Queue[dict[SensorId, list[SensorDataType]]]
] = None,
) -> float:
z_axis = Axis.by_mount(mount)
pos = self._position
Expand Down
12 changes: 11 additions & 1 deletion api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@
from .backends.flex_protocol import FlexBackend
from .backends.ot3simulator import OT3Simulator
from .backends.errors import SubsystemUpdating

from opentrons_hardware.firmware_bindings.constants import SensorId
from opentrons_hardware.sensors.types import SensorDataType

mod_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -2634,6 +2635,9 @@ async def _liquid_probe_pass(
probe: InstrumentProbeType,
p_travel: float,
force_both_sensors: bool = False,
response_queue: Optional[
asyncio.Queue[dict[SensorId, list[SensorDataType]]]
] = None,
) -> float:
plunger_direction = -1 if probe_settings.aspirate_while_sensing else 1
end_z = await self._backend.liquid_probe(
Expand All @@ -2646,6 +2650,7 @@ async def _liquid_probe_pass(
probe_settings.samples_for_baselining,
probe=probe,
force_both_sensors=force_both_sensors,
response_queue=response_queue,
)
machine_pos = await self._backend.update_position()
machine_pos[Axis.by_mount(mount)] = end_z
Expand All @@ -2666,6 +2671,9 @@ async def liquid_probe( # noqa: C901
probe_settings: Optional[LiquidProbeSettings] = None,
probe: Optional[InstrumentProbeType] = None,
force_both_sensors: bool = False,
response_queue: Optional[
asyncio.Queue[dict[SensorId, list[SensorDataType]]]
] = None,
) -> float:
"""Search for and return liquid level height.
Expand Down Expand Up @@ -2791,6 +2799,8 @@ async def prep_plunger_for_probe_move(
probe_settings,
checked_probe,
plunger_travel_mm + sensor_baseline_plunger_move_mm,
force_both_sensors,
response_queue,
)
# if we made it here without an error we found the liquid
error = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,17 @@ async def test_ready_for_movement(
assert controller.check_motor_status(axes) == ready


def probe_move_group_run_side_effect(head: NodeId, tool: NodeId) -> Iterator[Dict[NodeId, MotorPositionStatus]]:
def probe_move_group_run_side_effect(
head: NodeId, tool: NodeId
) -> Iterator[Dict[NodeId, MotorPositionStatus]]:
"""Return homed position for axis that is present and was commanded to home."""
positions = {
head: MotorPositionStatus(0.0, 0.0, True, True, MoveCompleteAck(1)),
tool: MotorPositionStatus(0.0, 0.0, True, True, MoveCompleteAck(1))}
tool: MotorPositionStatus(0.0, 0.0, True, True, MoveCompleteAck(1)),
}
yield positions


@pytest.mark.parametrize("mount", [OT3Mount.LEFT, OT3Mount.RIGHT])
async def test_liquid_probe(
mount: OT3Mount,
Expand All @@ -721,7 +725,9 @@ async def test_liquid_probe(
fake_max_p_dist = 70
head_node = axis_to_node(Axis.by_mount(mount))
tool_node = sensor_node_for_mount(mount)
mock_move_group_run.side_effect = probe_move_group_run_side_effect(head_node, tool_node)
mock_move_group_run.side_effect = probe_move_group_run_side_effect(
head_node, tool_node
)
try:
await controller.liquid_probe(
mount=mount,
Expand All @@ -740,7 +746,9 @@ async def test_liquid_probe(
# in tool_sensors, pipette moves down, then sensor move goes
print(move_groups)
assert move_groups[0][0][tool_node].stop_condition == MoveStopCondition.none
assert move_groups[1][0][tool_node].stop_condition == MoveStopCondition.sensor_report
assert (
move_groups[1][0][tool_node].stop_condition == MoveStopCondition.sensor_report
)
assert len(move_groups) == 2
assert move_groups[0][0][tool_node]
assert move_groups[1][0][head_node], move_groups[2][0][tool_node]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Test the tool-sensor coordination code."""
import logging
from mock import patch, AsyncMock, call
import os
import pytest
from contextlib import asynccontextmanager
from typing import Iterator, List, Tuple, AsyncIterator, Any, Dict, Callable
from opentrons_hardware.firmware_bindings.messages.message_definitions import (
AddLinearMoveRequest,
ExecuteMoveGroupRequest,
MoveCompleted,
ReadFromSensorResponse,
Expand Down Expand Up @@ -50,7 +48,6 @@
SensorType,
SensorThresholdMode,
SensorOutputBinding,
MoveStopCondition,
)
from opentrons_hardware.sensors.scheduler import SensorScheduler
from opentrons_hardware.sensors.sensor_driver import SensorDriver
Expand Down Expand Up @@ -250,7 +247,6 @@ def move_responder(
)



@pytest.mark.parametrize(
"target_node,motor_node,distance,speed,",
[
Expand Down

0 comments on commit 59abe33

Please sign in to comment.