Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): home all gripper axis when a stall is detected #16579

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { RecoveryInProgress } from './RecoveryInProgress'
import { getErrorKind } from './utils'
import { RECOVERY_MAP } from './constants'
import { useHomeGripperZAxis } from './hooks'
import { useHomeGripper } from './hooks'

import type { LabwareDefinition2, RobotType } from '@opentrons/shared-data'
import type { RecoveryRoute, RouteStep, RecoveryContentProps } from './types'
Expand Down Expand Up @@ -90,7 +90,7 @@ export function ErrorRecoveryWizard(
routeUpdateActions,
})

useHomeGripperZAxis(props)
useHomeGripper(props)

return <ErrorRecoveryComponent errorKind={errorKind} {...props} />
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { renderHook, act } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'

import { useHomeGripperZAxis } from '../useHomeGripperZAxis'
import { useHomeGripper } from '../useHomeGripper'
import { RECOVERY_MAP } from '/app/organisms/ErrorRecoveryFlows/constants'

describe('useHomeGripperZAxis', () => {
describe('useHomeGripper', () => {
const mockRecoveryCommands = {
homeGripperZAxis: vi.fn().mockResolvedValue(undefined),
homeGripper: vi.fn().mockResolvedValue(undefined),
}

const mockRouteUpdateActions = {
Expand All @@ -28,7 +28,7 @@ describe('useHomeGripperZAxis', () => {

it('should home gripper Z axis when in manual gripper step and door is closed', async () => {
renderHook(() => {
useHomeGripperZAxis({
useHomeGripper({
recoveryCommands: mockRecoveryCommands,
routeUpdateActions: mockRouteUpdateActions,
recoveryMap: mockRecoveryMap,
Expand All @@ -43,15 +43,15 @@ describe('useHomeGripperZAxis', () => {
expect(mockRouteUpdateActions.handleMotionRouting).toHaveBeenCalledWith(
true
)
expect(mockRecoveryCommands.homeGripperZAxis).toHaveBeenCalled()
expect(mockRecoveryCommands.homeGripper).toHaveBeenCalled()
expect(mockRouteUpdateActions.handleMotionRouting).toHaveBeenCalledWith(
false
)
})

it('should go back to previous step when door is open', () => {
renderHook(() => {
useHomeGripperZAxis({
useHomeGripper({
recoveryCommands: mockRecoveryCommands,
routeUpdateActions: mockRouteUpdateActions,
recoveryMap: mockRecoveryMap,
Expand All @@ -60,12 +60,12 @@ describe('useHomeGripperZAxis', () => {
})

expect(mockRouteUpdateActions.goBackPrevStep).toHaveBeenCalled()
expect(mockRecoveryCommands.homeGripperZAxis).not.toHaveBeenCalled()
expect(mockRecoveryCommands.homeGripper).not.toHaveBeenCalled()
})

it('should not home again if already homed once', async () => {
const { rerender } = renderHook(() => {
useHomeGripperZAxis({
useHomeGripper({
recoveryCommands: mockRecoveryCommands,
routeUpdateActions: mockRouteUpdateActions,
recoveryMap: mockRecoveryMap,
Expand All @@ -77,17 +77,17 @@ describe('useHomeGripperZAxis', () => {
await new Promise(resolve => setTimeout(resolve, 0))
})

expect(mockRecoveryCommands.homeGripperZAxis).toHaveBeenCalledTimes(1)
expect(mockRecoveryCommands.homeGripper).toHaveBeenCalledTimes(1)

rerender()

expect(mockRecoveryCommands.homeGripperZAxis).toHaveBeenCalledTimes(1)
expect(mockRecoveryCommands.homeGripper).toHaveBeenCalledTimes(1)
})

it('should reset hasHomedOnce when step changes to non-manual gripper step and back', async () => {
const { rerender } = renderHook(
({ recoveryMap }) => {
useHomeGripperZAxis({
useHomeGripper({
recoveryCommands: mockRecoveryCommands,
routeUpdateActions: mockRouteUpdateActions,
recoveryMap,
Expand All @@ -103,7 +103,7 @@ describe('useHomeGripperZAxis', () => {
await new Promise(resolve => setTimeout(resolve, 0))
})

expect(mockRecoveryCommands.homeGripperZAxis).toHaveBeenCalledTimes(1)
expect(mockRecoveryCommands.homeGripper).toHaveBeenCalledTimes(1)

rerender({ recoveryMap: { step: 'SOME_OTHER_STEP' } as any })

Expand All @@ -117,6 +117,6 @@ describe('useHomeGripperZAxis', () => {
await new Promise(resolve => setTimeout(resolve, 0))
})

expect(mockRecoveryCommands.homeGripperZAxis).toHaveBeenCalledTimes(2)
expect(mockRecoveryCommands.homeGripper).toHaveBeenCalledTimes(2)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RELEASE_GRIPPER_JAW,
buildPickUpTips,
buildIgnorePolicyRules,
HOME_GRIPPER_Z_AXIS,
HOME_GRIPPER,
} from '../useRecoveryCommands'
import { RECOVERY_MAP } from '../../constants'

Expand Down Expand Up @@ -264,17 +264,14 @@ describe('useRecoveryCommands', () => {
)
})

it('should call homeGripperZAxis and resolve the promise', async () => {
it('should call useHomeGripper and resolve the promise', async () => {
const { result } = renderHook(() => useRecoveryCommands(props))

await act(async () => {
await result.current.homeGripperZAxis()
await result.current.homeGripper()
})

expect(mockChainRunCommands).toHaveBeenCalledWith(
[HOME_GRIPPER_Z_AXIS],
false
)
expect(mockChainRunCommands).toHaveBeenCalledWith([HOME_GRIPPER], false)
})

it('should call skipFailedCommand and show success toast on success', async () => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/organisms/ErrorRecoveryFlows/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { useRouteUpdateActions } from './useRouteUpdateActions'
export { useERUtils } from './useERUtils'
export { useRecoveryTakeover } from './useRecoveryTakeover'
export { useRetainedFailedCommandBySource } from './useRetainedFailedCommandBySource'
export { useHomeGripperZAxis } from './useHomeGripperZAxis'
export { useHomeGripper } from './useHomeGripper'

export type { ERUtilsProps } from './useERUtils'
export type { UseRouteUpdateActionsResult } from './useRouteUpdateActions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RECOVERY_MAP } from '/app/organisms/ErrorRecoveryFlows/constants'
import type { ErrorRecoveryWizardProps } from '/app/organisms/ErrorRecoveryFlows/ErrorRecoveryWizard'

// Home the gripper z-axis implicitly. Because the z-home is not tied to a CTA, it must be handled here.
TamarZanzouri marked this conversation as resolved.
Show resolved Hide resolved
export function useHomeGripperZAxis({
export function useHomeGripper({
recoveryCommands,
routeUpdateActions,
recoveryMap,
Expand All @@ -20,15 +20,15 @@ export function useHomeGripperZAxis({

useLayoutEffect(() => {
const { handleMotionRouting, goBackPrevStep } = routeUpdateActions
const { homeGripperZAxis } = recoveryCommands
const { homeGripper } = recoveryCommands

if (!hasHomedOnce) {
if (isManualGripperStep) {
if (isDoorOpen) {
void goBackPrevStep()
} else {
void handleMotionRouting(true)
.then(() => homeGripperZAxis())
.then(() => homeGripper())
.then(() => {
setHasHomedOnce(true)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface UseRecoveryCommandsResult {
/* A non-terminal recovery command */
releaseGripperJaws: () => Promise<CommandData[]>
/* A non-terminal recovery command */
homeGripperZAxis: () => Promise<CommandData[]>
homeGripper: () => Promise<CommandData[]>
/* A non-terminal recovery command */
moveLabwareWithoutPause: () => Promise<CommandData[]>
}
Expand Down Expand Up @@ -269,8 +269,8 @@ export function useRecoveryCommands({
return chainRunRecoveryCommands([RELEASE_GRIPPER_JAW])
}, [chainRunRecoveryCommands])

const homeGripperZAxis = useCallback((): Promise<CommandData[]> => {
return chainRunRecoveryCommands([HOME_GRIPPER_Z_AXIS])
const homeGripper = useCallback((): Promise<CommandData[]> => {
return chainRunRecoveryCommands([HOME_GRIPPER])
}, [chainRunRecoveryCommands])

const moveLabwareWithoutPause = useCallback((): Promise<CommandData[]> => {
Expand All @@ -291,7 +291,7 @@ export function useRecoveryCommands({
homePipetteZAxes,
pickUpTips,
releaseGripperJaws,
homeGripperZAxis,
homeGripper,
moveLabwareWithoutPause,
skipFailedCommand,
ignoreErrorKindThisRun,
Expand All @@ -310,9 +310,9 @@ export const RELEASE_GRIPPER_JAW: CreateCommand = {
intent: 'fixit',
}

export const HOME_GRIPPER_Z_AXIS: CreateCommand = {
export const HOME_GRIPPER: CreateCommand = {
commandType: 'home',
params: { axes: ['extensionZ'] },
params: { axes: ['extensionZ', 'extensionJaw'] },
intent: 'fixit',
}

Expand Down
Loading