Skip to content

Commit

Permalink
home gripper axis if stall detected
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Oct 23, 2024
1 parent 18598cf commit 3473e13
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ export function ActionButton(props: ActionButtonProps): JSX.Element {
const isValidRunAgain = isRunAgainStatus(runStatus)
const { isClosingCurrentRun } = useCloseCurrentRun()

const { isDisabled, disabledReason } = useActionBtnDisabledUtils({
isCurrentRun,
isSetupComplete,
isOtherRunCurrent,
isProtocolNotReady,
isRobotOnWrongVersionOfSoftware,
isValidRunAgain,
isClosingCurrentRun,
...props,
})
// const { isDisabled, disabledReason } = useActionBtnDisabledUtils({
// isCurrentRun,
// isSetupComplete,
// isOtherRunCurrent,
// isProtocolNotReady,
// isRobotOnWrongVersionOfSoftware,
// isValidRunAgain,
// isClosingCurrentRun,
// ...props,
// })

const isDisabled = false
const disabledReason = ''

const robot = useRobot(robotName)
const robotSerialNumber = getFallbackRobotSerialNumber(robot)
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 '../useHomeGripperZAxis'
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 @@ -264,11 +264,11 @@ 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(
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 './useHomeGripperZAxis'

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.
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
18 changes: 14 additions & 4 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useRecoveryCommands.ts
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,12 @@ 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[]> => {
const gripperAxis =
failedCommandByRunRecord?.error?.errorCode === '2003'
? HOME_GRIPPER
: HOME_GRIPPER_Z_AXIS
return chainRunRecoveryCommands([gripperAxis])
}, [chainRunRecoveryCommands])

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

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

const buildMoveLabwareWithoutPause = (
failedCommand: FailedCommand | null
): CreateCommand | null => {
Expand Down

0 comments on commit 3473e13

Please sign in to comment.