Skip to content

Commit

Permalink
refactor(app): Use currentState for tip detection (#16904)
Browse files Browse the repository at this point in the history
Closes EXEC-1027

After completing a run or during Error Recovery, the app runs tip detection logic to determine whether or not to pop the drop tip wizard. It does so by iterating through protocol analysis, keeping track of attached pipettes, and looking at specific tip exchange commands to determine whether a not a pipette has tips attached. While this approach works, it's both brittle (any changes to tip exchange commands breaks the logic) and also a command scanning operation.

Now that we have tip status on our new /runs/:runId/currentState endpoint, we have a more robust option for determining tip status. There's one caveat: the robot and this util do have ideas of when a tip should be considered attached. On the app, because we want to show drop tip wizard when there might be a tip attached, such as during a failed pick up tip command, we assume there is a tip attached. In this instance however, the robot server does not think a tip is attached. Unfortunately, there's no way around manually accounting for these differences, but luckily they are few, and it's still a significant improvement over tracking every tip exchange command.

There's another optimization we can make too: we don't actually need to poll /instruments for pipette data, because now, the only place we use that data is during the tip detection util. Instead, we can fetch it along with the other necessary resources when determineTipStatus is invoked.

In short, these changes give us:

* Much easier to reason about tip detection logic.
* Significantly less brittle.
* No command scanning.
* No /instruments polling.
  • Loading branch information
mjhuff authored Nov 22, 2024
1 parent 9bdd8c1 commit d0ff76c
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 666 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { useEffect } from 'react'

import { useHost } from '@opentrons/react-api-client'
import { RUN_STATUS_IDLE, RUN_STATUS_STOPPED } from '@opentrons/api-client'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'

import {
useDropTipWizardFlows,
useTipAttachmentStatus,
} from '/app/organisms/DropTipWizardFlows'
import { useDropTipWizardFlows } from '/app/organisms/DropTipWizardFlows'
import { useProtocolDropTipModal } from '../modals'
import {
useCloseCurrentRun,
Expand All @@ -16,13 +12,12 @@ import {
} from '/app/resources/runs'
import { isTerminalRunStatus } from '../../utils'
import { lastRunCommandPromptedErrorRecovery } from '/app/local-resources/commands'
import { useTipAttachmentStatus } from '/app/resources/instruments'

import type { RobotType } from '@opentrons/shared-data'
import type { Run, RunStatus } from '@opentrons/api-client'
import type {
DropTipWizardFlowsProps,
PipetteWithTip,
} from '/app/organisms/DropTipWizardFlows'
import type { PipetteWithTip } from '/app/resources/instruments'
import type { DropTipWizardFlowsProps } from '/app/organisms/DropTipWizardFlows'
import type { UseProtocolDropTipModalResult } from '../modals'
import type { PipetteDetails } from '/app/resources/maintenance_runs'

Expand All @@ -49,7 +44,6 @@ export function useRunHeaderDropTip({
robotType,
runStatus,
}: UseRunHeaderDropTipParams): UseRunHeaderDropTipResult {
const host = useHost()
const isRunCurrent = useIsRunCurrent(runId)
const enteredER = runRecord?.data.hasEverEnteredErrorRecovery ?? false

Expand All @@ -66,7 +60,6 @@ export function useRunHeaderDropTip({
} = useTipAttachmentStatus({
runId,
runRecord: runRecord ?? null,
host,
})

const dropTipModalUtils = useProtocolDropTipModal({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useHomePipettes } from '/app/local-resources/instruments'
import type { PipetteData } from '@opentrons/api-client'
import type { IconProps } from '@opentrons/components'
import type { UseHomePipettesProps } from '/app/local-resources/instruments'
import type { TipAttachmentStatusResult } from '/app/organisms/DropTipWizardFlows'
import type { TipAttachmentStatusResult } from '/app/resources/instruments'

type UseProtocolDropTipModalProps = Pick<
UseHomePipettesProps,
Expand Down
2 changes: 1 addition & 1 deletion app/src/organisms/DropTipWizardFlows/TipsAttachedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { useHomePipettes } from '/app/local-resources/instruments'
import type { HostConfig } from '@opentrons/api-client'
import type { OddModalHeaderBaseProps } from '/app/molecules/OddModal/types'
import type { UseHomePipettesProps } from '/app/local-resources/instruments'
import type { PipetteWithTip } from './hooks'
import type { PipetteDetails } from '/app/resources/maintenance_runs'
import type { PipetteWithTip } from '/app/resources/instruments'

type TipsAttachedModalProps = Pick<UseHomePipettesProps, 'onSettled'> & {
aPipetteWithTip: PipetteWithTip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useDropTipWizardFlows } from '..'
import type { Mock } from 'vitest'
import type { PipetteModelSpecs } from '@opentrons/shared-data'
import type { HostConfig } from '@opentrons/api-client'
import type { PipetteWithTip } from '../hooks'
import type { PipetteWithTip } from '/app/resources/instruments'

vi.mock('/app/resources/runs/useCloseCurrentRun')
vi.mock('..')
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion app/src/organisms/DropTipWizardFlows/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './errors'
export * from './useDropTipWithType'
export * from './useTipAttachmentStatus'
export * from './useDropTipLocations'
export { useDropTipRouting } from './useDropTipRouting'
export { useDropTipWithType } from './useDropTipWithType'
Expand Down
Loading

0 comments on commit d0ff76c

Please sign in to comment.