Skip to content

Commit

Permalink
udpate jaw state in ot3simulator (#13522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau authored Sep 12, 2023
1 parent fd5cea2 commit 8abc1ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
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 @@ -188,6 +188,7 @@ def _sanitize_attached_instrument(
nodes.add(NodeId.gripper)
self._present_nodes = nodes
self._current_settings: Optional[OT3AxisMap[CurrentConfig]] = None
self._sim_jaw_state = GripperJawState.HOMED_READY

@property
def initialized(self) -> bool:
Expand Down Expand Up @@ -369,12 +370,14 @@ async def gripper_grip_jaw(
) -> None:
"""Move gripper inward."""
_ = create_gripper_jaw_grip_group(duty_cycle, stop_condition, stay_engaged)
self._sim_jaw_state = GripperJawState.GRIPPING

@ensure_yield
async def gripper_home_jaw(self, duty_cycle: float) -> None:
"""Move gripper outward."""
_ = create_gripper_jaw_home_group(duty_cycle)
self._motor_status[NodeId.gripper_g] = MotorStatus(True, True)
self._sim_jaw_state = GripperJawState.HOMED_READY

@ensure_yield
async def gripper_hold_jaw(
Expand All @@ -383,6 +386,7 @@ async def gripper_hold_jaw(
) -> None:
_ = create_gripper_jaw_hold_group(encoder_position_um)
self._encoder_position[NodeId.gripper_g] = encoder_position_um / 1000.0
self._sim_jaw_state = GripperJawState.HOLDING

async def get_tip_present(self, mount: OT3Mount, tip_state: TipStateType) -> None:
"""Raise an error if the given state doesn't match the physical state."""
Expand All @@ -394,7 +398,7 @@ async def get_tip_present_state(self, mount: OT3Mount) -> int:

async def get_jaw_state(self) -> GripperJawState:
"""Get the state of the gripper jaw."""
return GripperJawState.HOMED_READY
return self._sim_jaw_state

async def tip_action(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def move_labware_with_gripper(

for waypoint_data in movement_waypoints:
if waypoint_data.jaw_open:
await ot3api.home_gripper_jaw()
await ot3api.ungrip()
else:
await ot3api.grip(force_newtons=labware_grip_force)
await ot3api.move_to(
Expand Down
16 changes: 0 additions & 16 deletions api/tests/opentrons/hardware_control/test_ot3_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,6 @@ def mock_move_to(ot3_hardware: ThreadManager[OT3API]) -> Iterator[AsyncMock]:
yield mock_move


@pytest.fixture
def mock_get_jaw_state(ot3_hardware: ThreadManager[OT3API]) -> Iterator[AsyncMock]:
with patch.object(
ot3_hardware.managed_obj._backend,
"get_jaw_state",
AsyncMock(
spec=ot3_hardware.managed_obj._backend.get_jaw_state,
wraps=ot3_hardware.managed_obj._backend.get_jaw_state,
),
) as mock_get_jaw_state:
yield mock_get_jaw_state


@pytest.fixture
def mock_home(ot3_hardware: ThreadManager[OT3API]) -> Iterator[AsyncMock]:
with patch.object(
Expand Down Expand Up @@ -852,14 +839,12 @@ async def test_gripper_capacitive_sweep(
distance: float,
ot3_hardware: ThreadManager[OT3API],
mock_move_to: AsyncMock,
mock_get_jaw_state: AsyncMock,
mock_backend_capacitive_pass: AsyncMock,
gripper_present: None,
) -> None:
await ot3_hardware.home()
await ot3_hardware.grip(5)
ot3_hardware._gripper_handler.get_gripper().current_jaw_displacement = 5
mock_get_jaw_state.return_value = GripperJawState.GRIPPING
ot3_hardware.add_gripper_probe(probe)
data = await ot3_hardware.capacitive_sweep(OT3Mount.GRIPPER, axis, begin, end, 3)
assert data == [1, 2, 3, 4, 5, 6, 8]
Expand Down Expand Up @@ -1783,7 +1768,6 @@ async def test_estop_event_deactivate_module(
async def test_stop_only_home_necessary_axes(
ot3_hardware: ThreadManager[OT3API],
mock_home: AsyncMock,
# mock_get_jaw_state: AsyncMock,
mock_reset: AsyncMock,
jaw_state: GripperJawState,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ async def test_move_labware_with_gripper(

decoy.when(state_store.config.use_virtual_gripper).then_return(False)
decoy.when(ot3_hardware_api.has_gripper()).then_return(True)
decoy.when(ot3_hardware_api._gripper_handler.is_ready_for_jaw_home()).then_return(
True
)

decoy.when(
await ot3_hardware_api.gantry_position(mount=OT3Mount.GRIPPER)
Expand Down

0 comments on commit 8abc1ba

Please sign in to comment.