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

feat(step-generation): generate py command for moveToAddressableArea #17849

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions step-generation/src/__tests__/airGapInTrash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ import type { CutoutId } from '@opentrons/shared-data'
import type { InvariantContext, RobotState } from '../types'

const mockCutout: CutoutId = 'cutoutA3'
const invariantContext: InvariantContext = makeContext()
const mockTrashId = 'mockTrashId'
const invariantContext: InvariantContext = {
...makeContext(),
additionalEquipmentEntities: {
[mockTrashId]: {
id: mockTrashId,
name: 'trashBin',
pythonName: 'mock_trash_bin_1',
location: mockCutout,
},
},
}
const prevRobotState: RobotState = getInitialRobotStateStandard(
invariantContext
)
Expand All @@ -22,7 +33,7 @@ describe('airGapInTrash', () => {
pipetteId: DEFAULT_PIPETTE,
volume: 10,
flowRate: 10,
trashLocation: mockCutout,
trashId: mockTrashId,
},
invariantContext,
prevRobotState
Expand Down
32 changes: 17 additions & 15 deletions step-generation/src/__tests__/airGapInWasteChute.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { describe, it, expect } from 'vitest'
import { WASTE_CHUTE_CUTOUT } from '@opentrons/shared-data'
import {
DEFAULT_PIPETTE,
getInitialRobotStateStandard,
getSuccessResult,
makeContext,
} from '../fixtures'
import { airGapInWasteChute } from '../commandCreators/compound'
import type { InvariantContext, PipetteEntities, RobotState } from '../types'

const mockId = 'mockId'
const mockPipEntities: PipetteEntities = {
[mockId]: {
name: 'p50_single_flex',
id: mockId,
spec: { channels: 1 },
},
} as any
import type { InvariantContext, RobotState } from '../types'

const wasteChuteId = 'wasteChuteId'
const invariantContext: InvariantContext = {
...makeContext(),
pipetteEntities: mockPipEntities,
additionalEquipmentEntities: {
[wasteChuteId]: {
id: wasteChuteId,
name: 'wasteChute',
pythonName: 'mock_waste_chute_1',
location: WASTE_CHUTE_CUTOUT,
},
},
}
const prevRobotState: RobotState = getInitialRobotStateStandard(
invariantContext
Expand All @@ -28,9 +29,10 @@ describe('airGapInWasteChute', () => {
it('returns correct commands for air gap in waste chute', () => {
const result = airGapInWasteChute(
{
pipetteId: mockId,
pipetteId: DEFAULT_PIPETTE,
volume: 10,
flowRate: 10,
wasteChuteId,
},
invariantContext,
prevRobotState
Expand All @@ -40,7 +42,7 @@ describe('airGapInWasteChute', () => {
commandType: 'moveToAddressableArea',
key: expect.any(String),
params: {
pipetteId: mockId,
pipetteId: DEFAULT_PIPETTE,
addressableAreaName: '1ChannelWasteChute',
offset: { x: 0, y: 0, z: 0 },
},
Expand All @@ -49,14 +51,14 @@ describe('airGapInWasteChute', () => {
commandType: 'prepareToAspirate',
key: expect.any(String),
params: {
pipetteId: mockId,
pipetteId: DEFAULT_PIPETTE,
},
},
{
commandType: 'airGapInPlace',
key: expect.any(String),
params: {
pipetteId: mockId,
pipetteId: DEFAULT_PIPETTE,
flowRate: 10,
volume: 10,
},
Expand Down
91 changes: 71 additions & 20 deletions step-generation/src/__tests__/moveToAddressableArea.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,95 @@
import { describe, it, expect } from 'vitest'
import { getSuccessResult } from '../fixtures'
import { WASTE_CHUTE_CUTOUT } from '@opentrons/shared-data'
import {
getSuccessResult,
makeContext,
getInitialRobotStateStandard,
DEFAULT_PIPETTE,
} from '../fixtures'
import { moveToAddressableArea } from '../commandCreators/atomic'
import type { InvariantContext, RobotState } from '../types'
import type { CutoutId } from '@opentrons/shared-data'

const getRobotInitialState = (): any => {
return {}
}
const mockId = 'mockId'
const invariantContext: any = {
pipetteEntities: {
[mockId]: {
name: 'p50_single_flex',
id: mockId,
const mockCutout = 'cutoutA3' as CutoutId
const mockTrashId = 'mockTrashId'
let invariantContext: InvariantContext = {
...makeContext(),
additionalEquipmentEntities: {
[mockTrashId]: {
id: mockTrashId,
name: 'trashBin',
pythonName: 'mock_trash_bin_1',
location: mockCutout,
},
},
}
const prevRobotState: RobotState = getInitialRobotStateStandard(
invariantContext
)

describe('moveToAddressableArea', () => {
it('should call moveToAddressableArea with correct params', () => {
const robotInitialState = getRobotInitialState()
const mockName = '1ChannelWasteChute'
it('should call moveToAddressableArea with correct params for trash bin', () => {
const result = moveToAddressableArea(
{
pipetteId: DEFAULT_PIPETTE,
fixtureId: mockTrashId,
offset: { x: 0, y: 0, z: 1 },
},
invariantContext,
prevRobotState
)
const res = getSuccessResult(result)
expect(res.commands).toEqual([
{
commandType: 'moveToAddressableArea',
key: expect.any(String),
params: {
pipetteId: DEFAULT_PIPETTE,
addressableAreaName: 'movableTrashA3',
offset: { x: 0, y: 0, z: 1 },
},
},
])
expect(getSuccessResult(result).python).toBe(
'mockPythonName.move_to(mock_trash_bin_1)'
)
})
it('should call moveToAddressableArea with correct params for waste chute', () => {
const wasteChuteId = 'wasteChuteId'
invariantContext = {
...invariantContext,
additionalEquipmentEntities: {
[wasteChuteId]: {
id: wasteChuteId,
name: 'wasteChute',
pythonName: 'mock_waste_chute_1',
location: WASTE_CHUTE_CUTOUT,
},
},
}
const result = moveToAddressableArea(
{
pipetteId: mockId,
addressableAreaName: mockName,
offset: { x: 0, y: 0, z: 0 },
pipetteId: DEFAULT_PIPETTE,
fixtureId: wasteChuteId,
offset: { x: 0, y: 0, z: 1 },
},
invariantContext,
robotInitialState
prevRobotState
)
const res = getSuccessResult(result)
expect(res.commands).toEqual([
{
commandType: 'moveToAddressableArea',
key: expect.any(String),
params: {
pipetteId: mockId,
addressableAreaName: mockName,
offset: { x: 0, y: 0, z: 0 },
pipetteId: DEFAULT_PIPETTE,
addressableAreaName: '1ChannelWasteChute',
offset: { x: 0, y: 0, z: 1 },
},
},
])
expect(getSuccessResult(result).python).toBe(
'mockPythonName.move_to(mock_waste_chute_1)'
)
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import { uuid } from '../../utils'
import type { MoveToAddressableAreaParams } from '@opentrons/shared-data'
import {
getTrashBinAddressableAreaName,
getWasteChuteAddressableAreaNamePip,
uuid,
} from '../../utils'
import type {
AddressableAreaName,
CutoutId,
MoveToAddressableAreaParams,
} from '@opentrons/shared-data'
import type { CommandCreator } from '../../types'

export const moveToAddressableArea: CommandCreator<MoveToAddressableAreaParams> = (
interface MoveToAddressableAreaAtomicParams
extends Omit<MoveToAddressableAreaParams, 'addressableAreaName'> {
fixtureId: string
}
export const moveToAddressableArea: CommandCreator<MoveToAddressableAreaAtomicParams> = (
args,
invariantContext,
prevRobotState
) => {
const { pipetteId, addressableAreaName, offset } = args
const { pipetteId, fixtureId, offset } = args
const { pipetteEntities, additionalEquipmentEntities } = invariantContext
const pipetteEntity = pipetteEntities[pipetteId]
const pipetteChannels = pipetteEntity.spec.channels
const pipettePythonName = pipetteEntity.pythonName
const fixtureEntity = additionalEquipmentEntities[fixtureId]
const fixturePythonName = fixtureEntity.pythonName

let addressableAreaName: AddressableAreaName = getWasteChuteAddressableAreaNamePip(
pipetteChannels
)
if (fixtureEntity.name === 'trashBin') {
addressableAreaName = getTrashBinAddressableAreaName(
fixtureEntity.location as CutoutId
)
}

const commands = [
{
Expand All @@ -22,5 +49,6 @@ export const moveToAddressableArea: CommandCreator<MoveToAddressableAreaParams>
]
return {
commands,
python: `${pipettePythonName}.move_to(${fixturePythonName})`,
}
}
14 changes: 4 additions & 10 deletions step-generation/src/commandCreators/compound/airGapInTrash.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import {
getTrashBinAddressableAreaName,
reduceCommandCreators,
curryCommandCreator,
} from '../../utils'
import { reduceCommandCreators, curryCommandCreator } from '../../utils'
import { ZERO_OFFSET } from '../../constants'
import {
airGapInPlace,
moveToAddressableArea,
prepareToAspirate,
} from '../atomic'
import type { CurriedCommandCreator, CommandCreator } from '../../types'
import type { CutoutId } from '@opentrons/shared-data'

interface AirGapInTrashParams {
pipetteId: string
flowRate: number
volume: number
trashLocation: CutoutId
trashId: string
}
export const airGapInTrash: CommandCreator<AirGapInTrashParams> = (
args,
invariantContext,
prevRobotState
) => {
const { pipetteId, trashLocation, flowRate, volume } = args
const addressableAreaName = getTrashBinAddressableAreaName(trashLocation)
const { pipetteId, trashId, flowRate, volume } = args
const commandCreators: CurriedCommandCreator[] = [
curryCommandCreator(moveToAddressableArea, {
pipetteId,
addressableAreaName,
fixtureId: trashId,
offset: ZERO_OFFSET,
}),
curryCommandCreator(prepareToAspirate, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
curryCommandCreator,
getWasteChuteAddressableAreaNamePip,
reduceCommandCreators,
} from '../../utils'
import { curryCommandCreator, reduceCommandCreators } from '../../utils'
import { ZERO_OFFSET } from '../../constants'
import {
airGapInPlace,
Expand All @@ -15,24 +11,20 @@ interface AirGapInWasteChuteArgs {
pipetteId: string
volume: number
flowRate: number
wasteChuteId: string
}

export const airGapInWasteChute: CommandCreator<AirGapInWasteChuteArgs> = (
args,
invariantContext,
prevRobotState
) => {
const { pipetteId, volume, flowRate } = args
const pipetteChannels =
invariantContext.pipetteEntities[pipetteId].spec.channels
const addressableAreaName = getWasteChuteAddressableAreaNamePip(
pipetteChannels
)
const { pipetteId, volume, flowRate, wasteChuteId } = args

const commandCreators: CurriedCommandCreator[] = [
curryCommandCreator(moveToAddressableArea, {
pipetteId,
addressableAreaName,
fixtureId: wasteChuteId,
offset: ZERO_OFFSET,
}),
curryCommandCreator(prepareToAspirate, {
Expand Down
12 changes: 2 additions & 10 deletions step-generation/src/commandCreators/compound/blowOutInTrash.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
getTrashBinAddressableAreaName,
reduceCommandCreators,
curryWithoutPython,
} from '../../utils'
import { reduceCommandCreators, curryWithoutPython } from '../../utils'
import { ZERO_OFFSET } from '../../constants'
import { blowOutInPlace, moveToAddressableArea } from '../atomic'
import type { CurriedCommandCreator, CommandCreator } from '../../types'
import type { CutoutId } from '@opentrons/shared-data'

interface BlowOutInTrashParams {
pipetteId: string
Expand All @@ -21,9 +16,6 @@ export const blowOutInTrash: CommandCreator<BlowOutInTrashParams> = (
const { pipetteId, trashId, flowRate } = args
const { pipetteEntities, additionalEquipmentEntities } = invariantContext
const trashEntity = additionalEquipmentEntities[trashId]
const addressableAreaName = getTrashBinAddressableAreaName(
trashEntity.location as CutoutId
)
const pipettePythonName = pipetteEntities[pipetteId].pythonName
const trashPythonName = trashEntity.pythonName

Expand All @@ -38,7 +30,7 @@ export const blowOutInTrash: CommandCreator<BlowOutInTrashParams> = (
const commandCreators = [
curryWithoutPython(moveToAddressableArea, {
pipetteId,
addressableAreaName,
fixtureId: trashId,
offset: ZERO_OFFSET,
}),
curryWithoutPython(blowOutInPlace, {
Expand Down
Loading
Loading