1
1
import { getAddressableAreasInProtocol , getDeckDefFromRobotType } from '.'
2
- import { FLEX_ROBOT_TYPE } from '../constants'
3
- import {
4
- getAddressableAreaFromSlotId ,
5
- getMainNonComboFixtureId ,
6
- } from '../fixtures'
2
+ import { COMBINATION_FIXTURES , FLEX_ROBOT_TYPE } from '../constants'
3
+ import { getAddressableAreaFromSlotId } from '../fixtures'
7
4
8
5
import type { AddressableAreaName , CutoutFixtureId , CutoutId } from '../../deck'
9
6
import type { ProtocolAnalysisOutput } from '../../protocol'
@@ -42,31 +39,36 @@ export const FLEX_SIMPLEST_DECK_CONFIG_PROTOCOL_SPEC: CutoutConfigProtocolSpec[]
42
39
export function getSimplestDeckConfigForProtocol (
43
40
protocolAnalysis : CompletedProtocolAnalysis | ProtocolAnalysisOutput | null
44
41
) : CutoutConfigProtocolSpec [ ] {
45
- // TODO(BC, 2023-11-06): abstract out the robot type
46
42
const deckDef = getDeckDefFromRobotType ( FLEX_ROBOT_TYPE )
47
43
48
44
const addressableAreas =
49
45
protocolAnalysis != null
50
46
? getAddressableAreasInProtocol ( protocolAnalysis , deckDef )
51
47
: [ ]
48
+ // iterates through the list of required addressable areas for the protocol
52
49
const simplestDeckConfig = addressableAreas . reduce <
53
50
CutoutConfigProtocolSpec [ ]
54
51
> ( ( acc , addressableArea ) => {
52
+ // finds all cutout fixtures that provide this addressable area
55
53
const cutoutFixturesForAddressableArea = getCutoutFixturesForAddressableAreas (
56
54
[ addressableArea ] ,
57
55
deckDef . cutoutFixtures
58
56
)
57
+ // grabs the cutout id for the addressable area
59
58
const cutoutIdForAddressableArea = getCutoutIdForAddressableArea (
60
59
addressableArea ,
61
60
cutoutFixturesForAddressableArea
62
61
)
62
+ // grabs all possible cutout fixtures for that cutout id
63
63
const cutoutFixturesForCutoutId =
64
64
cutoutIdForAddressableArea != null
65
65
? getCutoutFixturesForCutoutId (
66
66
cutoutIdForAddressableArea ,
67
67
deckDef . cutoutFixtures
68
68
)
69
69
: null
70
+
71
+ // finds what is currently in that specific cutout
70
72
const existingCutoutConfig = acc . find (
71
73
cutoutConfig => cutoutConfig . cutoutId === cutoutIdForAddressableArea
72
74
)
@@ -76,32 +78,33 @@ export function getSimplestDeckConfigForProtocol(
76
78
cutoutFixturesForCutoutId != null &&
77
79
cutoutIdForAddressableArea != null
78
80
) {
79
- const indexOfExistingFixture = cutoutFixturesForCutoutId . findIndex (
80
- ( { id } ) => id === existingCutoutConfig . cutoutFixtureId
81
- )
81
+ // finds what index in out accumulated deck config object that cutout is at
82
+ // so that we can see if we've already added a fixture for a different
83
+ // addressable area located at the same cutout. this would mean we need to change it
84
+ // to be a combination fixture
82
85
const accIndex = acc . findIndex (
83
86
( { cutoutId } ) => cutoutId === cutoutIdForAddressableArea
84
87
)
88
+ // what addressable areas we've already looped through and added to this cutout
85
89
const previousRequiredAAs = acc [ accIndex ] ?. requiredAddressableAreas
90
+
91
+ // what addressable area we're currently looking at and need to incorporate
86
92
const allNextRequiredAddressableAreas =
87
93
previousRequiredAAs != null &&
88
94
previousRequiredAAs . includes ( addressableArea )
89
95
? previousRequiredAAs
90
96
: [ ...previousRequiredAAs , addressableArea ]
91
97
98
+ // check for the next compatible fixture for the new, longer list of addressable areas
92
99
const nextCompatibleCutoutFixture = getSimplestFixtureForAddressableAreas (
93
100
cutoutIdForAddressableArea ,
94
101
allNextRequiredAddressableAreas ,
95
102
cutoutFixturesForCutoutId
96
103
)
97
- const indexOfCurrentFixture = cutoutFixturesForCutoutId . findIndex (
98
- ( { id } ) => id === nextCompatibleCutoutFixture ?. id
99
- )
100
104
101
- if (
102
- nextCompatibleCutoutFixture != null &&
103
- indexOfCurrentFixture > indexOfExistingFixture
104
- ) {
105
+ // this logic swaps out the newly found cutoutfixture id with the existing one
106
+ // that was added for the last addressable area we referenced
107
+ if ( nextCompatibleCutoutFixture != null ) {
105
108
return [
106
109
...acc . slice ( 0 , accIndex ) ,
107
110
{
@@ -187,20 +190,14 @@ export function getSimplestFixtureForAddressableAreas(
187
190
cutoutId ,
188
191
allCutoutFixtures
189
192
)
193
+
190
194
const nextCompatibleCutoutFixtures = getCutoutFixturesForAddressableAreas (
191
195
requiredAddressableAreas ,
192
196
cutoutFixturesForCutoutId
193
197
)
194
- if ( nextCompatibleCutoutFixtures . length > 1 ) {
195
- const mainFixture = getMainNonComboFixtureId (
196
- nextCompatibleCutoutFixtures . map ( cf => cf . id ) ,
197
- requiredAddressableAreas ,
198
- cutoutId
199
- )
200
- return (
201
- nextCompatibleCutoutFixtures . find ( cf => cf . id === mainFixture ) ?? null
202
- )
203
- } else {
204
- return nextCompatibleCutoutFixtures ?. [ 0 ] ?? null
205
- }
198
+ const nonComboFixture = nextCompatibleCutoutFixtures . find (
199
+ fixture => ! COMBINATION_FIXTURES . includes ( fixture . id )
200
+ )
201
+
202
+ return nonComboFixture ?? nextCompatibleCutoutFixtures ?. [ 0 ] ?? null
206
203
}
0 commit comments