Skip to content

Commit 7e44ff5

Browse files
authored
feat(step-generation): py command for dispensing in trash (#17827)
1 parent 1a4b4a0 commit 7e44ff5

File tree

3 files changed

+110
-16
lines changed

3 files changed

+110
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
import { describe, it, expect, vi } from 'vitest'
22
import {
3+
DEFAULT_PIPETTE,
34
getInitialRobotStateStandard,
45
getSuccessResult,
56
makeContext,
67
} from '../fixtures'
78
import { dispenseInTrash } from '../commandCreators/compound'
89
import type { CutoutId } from '@opentrons/shared-data'
910
import type { InvariantContext, RobotState } from '../types'
11+
import { PROTOCOL_CONTEXT_NAME } from '../utils'
1012

1113
vi.mock('../getNextRobotStateAndWarnings/dispenseUpdateLiquidState')
1214

13-
const mockId = 'mockId'
1415
const mockCutout: CutoutId = 'cutoutA3'
15-
const invariantContext: InvariantContext = makeContext()
16+
const mockTrashId = 'mockTrashId'
17+
let invariantContext: InvariantContext = {
18+
...makeContext(),
19+
additionalEquipmentEntities: {
20+
[mockTrashId]: {
21+
id: mockTrashId,
22+
name: 'trashBin',
23+
pythonName: 'mock_trash_bin_1',
24+
location: mockCutout,
25+
},
26+
},
27+
}
1628
const prevRobotState: RobotState = getInitialRobotStateStandard(
1729
invariantContext
1830
)
1931

2032
describe('dispenseInTrash', () => {
21-
it('returns correct commands for dispenseInTrash in trash bin', () => {
33+
it('returns correct commands for dispenseInTrash in trash bin for flex', () => {
2234
const result = dispenseInTrash(
2335
{
24-
pipetteId: mockId,
36+
pipetteId: DEFAULT_PIPETTE,
2537
flowRate: 10,
2638
volume: 10,
27-
trashLocation: mockCutout,
39+
trashId: mockTrashId,
2840
},
2941
invariantContext,
3042
prevRobotState
@@ -34,7 +46,7 @@ describe('dispenseInTrash', () => {
3446
commandType: 'moveToAddressableArea',
3547
key: expect.any(String),
3648
params: {
37-
pipetteId: mockId,
49+
pipetteId: DEFAULT_PIPETTE,
3850
addressableAreaName: 'movableTrashA3',
3951
offset: { x: 0, y: 0, z: 0 },
4052
},
@@ -43,11 +55,71 @@ describe('dispenseInTrash', () => {
4355
commandType: 'dispenseInPlace',
4456
key: expect.any(String),
4557
params: {
46-
pipetteId: mockId,
58+
pipetteId: DEFAULT_PIPETTE,
4759
volume: 10,
4860
flowRate: 10,
4961
},
5062
},
5163
])
64+
expect(getSuccessResult(result).python).toBe(
65+
`
66+
mockPythonName.dispense(
67+
volume=10,
68+
location=mock_trash_bin_1,
69+
rate=10 / mockPythonName.flow_rate.dispense,
70+
)`.trimStart()
71+
)
72+
})
73+
it('returns correct commands for dispenseInTrash in trash bin for ot-2', () => {
74+
const mockFixedTrashId = 'fixedTrashId'
75+
invariantContext = {
76+
...invariantContext,
77+
additionalEquipmentEntities: {
78+
[mockFixedTrashId]: {
79+
id: mockFixedTrashId,
80+
name: 'trashBin',
81+
pythonName: `${PROTOCOL_CONTEXT_NAME}.fixed_trash`,
82+
location: 'cutout12',
83+
},
84+
},
85+
}
86+
const result = dispenseInTrash(
87+
{
88+
pipetteId: DEFAULT_PIPETTE,
89+
flowRate: 10,
90+
volume: 10,
91+
trashId: mockFixedTrashId,
92+
},
93+
invariantContext,
94+
prevRobotState
95+
)
96+
expect(getSuccessResult(result).commands).toEqual([
97+
{
98+
commandType: 'moveToAddressableArea',
99+
key: expect.any(String),
100+
params: {
101+
pipetteId: DEFAULT_PIPETTE,
102+
addressableAreaName: 'fixedTrash',
103+
offset: { x: 0, y: 0, z: 0 },
104+
},
105+
},
106+
{
107+
commandType: 'dispenseInPlace',
108+
key: expect.any(String),
109+
params: {
110+
pipetteId: DEFAULT_PIPETTE,
111+
volume: 10,
112+
flowRate: 10,
113+
},
114+
},
115+
])
116+
expect(getSuccessResult(result).python).toBe(
117+
`
118+
mockPythonName.dispense(
119+
volume=10,
120+
location=protocol.fixed_trash,
121+
rate=10 / mockPythonName.flow_rate.dispense,
122+
)`.trimStart()
123+
)
52124
})
53125
})

step-generation/src/commandCreators/compound/dispenseInTrash.ts

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
getTrashBinAddressableAreaName,
33
reduceCommandCreators,
4-
curryCommandCreator,
4+
indentPyLines,
5+
curryWithoutPython,
56
} from '../../utils'
67
import { ZERO_OFFSET } from '../../constants'
78
import { dispenseInPlace, moveToAddressableArea } from '../atomic'
@@ -12,26 +13,48 @@ interface DispenseInTrashParams {
1213
pipetteId: string
1314
flowRate: number
1415
volume: number
15-
trashLocation: CutoutId
16+
trashId: string
1617
}
1718
export const dispenseInTrash: CommandCreator<DispenseInTrashParams> = (
1819
args,
1920
invariantContext,
2021
prevRobotState
2122
) => {
22-
const { pipetteId, trashLocation, flowRate, volume } = args
23-
const addressableAreaName = getTrashBinAddressableAreaName(trashLocation)
24-
const commandCreators: CurriedCommandCreator[] = [
25-
curryCommandCreator(moveToAddressableArea, {
23+
const { pipetteId, trashId, flowRate, volume } = args
24+
const { pipetteEntities, additionalEquipmentEntities } = invariantContext
25+
const trashEntity = additionalEquipmentEntities[trashId]
26+
const addressableAreaName = getTrashBinAddressableAreaName(
27+
trashEntity.location as CutoutId
28+
)
29+
const pipettePythonName = pipetteEntities[pipetteId].pythonName
30+
const trashPythonName = trashEntity.pythonName
31+
const pythonArgs = [
32+
`volume=${volume}`,
33+
`location=${trashPythonName}`,
34+
// rate= is a ratio in the PAPI, and we have no good way to figure out what
35+
// flowrate the PAPI has set the pipette to, so we just have to emit a division:
36+
`rate=${flowRate} / ${pipettePythonName}.flow_rate.dispense`,
37+
]
38+
39+
const pythonCommandCreator: CurriedCommandCreator = () => ({
40+
commands: [],
41+
python: `${pipettePythonName}.dispense(\n${indentPyLines(
42+
pythonArgs.join(',\n')
43+
)},\n)`,
44+
})
45+
46+
const commandCreators = [
47+
curryWithoutPython(moveToAddressableArea, {
2648
pipetteId,
2749
addressableAreaName,
2850
offset: ZERO_OFFSET,
2951
}),
30-
curryCommandCreator(dispenseInPlace, {
52+
curryWithoutPython(dispenseInPlace, {
3153
pipetteId,
3254
volume,
3355
flowRate,
3456
}),
57+
pythonCommandCreator,
3558
]
3659

3760
return reduceCommandCreators(

step-generation/src/utils/misc.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ export const dispenseLocationHelper: CommandCreator<DispenseLocationHelperArgs>
629629
pipetteId,
630630
volume,
631631
flowRate,
632-
trashLocation: additionalEquipmentEntities[destinationId]
633-
.location as CutoutId,
632+
trashId: additionalEquipmentEntities[destinationId].id,
634633
}),
635634
]
636635
}

0 commit comments

Comments
 (0)