Skip to content

Commit b8787e0

Browse files
committed
Fix for waste chute + stacker combo fixtures getting overridden
1 parent 0d1db4c commit b8787e0

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

shared-data/js/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,11 @@ export const COMBO_FIXTURES: CutoutFixtureIdsWithFakes[] = [
811811
...FAKE_FIXTURE_IDS,
812812
...STAGING_AREA_FIXTURES,
813813
]
814+
815+
export const COMBINATION_FIXTURES: CutoutFixtureId[] = [
816+
FLEX_STACKER_WITH_MAG_BLOCK_FIXTURE,
817+
STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE,
818+
...WASTE_CHUTE_FLEX_STACKER_FIXTURES,
819+
...WASTE_CHUTE_STAGING_AREA_FIXTURES,
820+
]
821+

shared-data/js/helpers/getSimplestFlexDeckConfig.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
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'
74

85
import type { AddressableAreaName, CutoutFixtureId, CutoutId } from '../../deck'
96
import type { ProtocolAnalysisOutput } from '../../protocol'
@@ -42,31 +39,36 @@ export const FLEX_SIMPLEST_DECK_CONFIG_PROTOCOL_SPEC: CutoutConfigProtocolSpec[]
4239
export function getSimplestDeckConfigForProtocol(
4340
protocolAnalysis: CompletedProtocolAnalysis | ProtocolAnalysisOutput | null
4441
): CutoutConfigProtocolSpec[] {
45-
// TODO(BC, 2023-11-06): abstract out the robot type
4642
const deckDef = getDeckDefFromRobotType(FLEX_ROBOT_TYPE)
4743

4844
const addressableAreas =
4945
protocolAnalysis != null
5046
? getAddressableAreasInProtocol(protocolAnalysis, deckDef)
5147
: []
48+
// iterates through the list of required addressable areas for the protocol
5249
const simplestDeckConfig = addressableAreas.reduce<
5350
CutoutConfigProtocolSpec[]
5451
>((acc, addressableArea) => {
52+
// finds all cutout fixtures that provide this addressable area
5553
const cutoutFixturesForAddressableArea = getCutoutFixturesForAddressableAreas(
5654
[addressableArea],
5755
deckDef.cutoutFixtures
5856
)
57+
// grabs the cutout id for the addressable area
5958
const cutoutIdForAddressableArea = getCutoutIdForAddressableArea(
6059
addressableArea,
6160
cutoutFixturesForAddressableArea
6261
)
62+
// grabs all possible cutout fixtures for that cutout id
6363
const cutoutFixturesForCutoutId =
6464
cutoutIdForAddressableArea != null
6565
? getCutoutFixturesForCutoutId(
6666
cutoutIdForAddressableArea,
6767
deckDef.cutoutFixtures
6868
)
6969
: null
70+
71+
// finds what is currently in that specific cutout
7072
const existingCutoutConfig = acc.find(
7173
cutoutConfig => cutoutConfig.cutoutId === cutoutIdForAddressableArea
7274
)
@@ -76,32 +78,33 @@ export function getSimplestDeckConfigForProtocol(
7678
cutoutFixturesForCutoutId != null &&
7779
cutoutIdForAddressableArea != null
7880
) {
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
8285
const accIndex = acc.findIndex(
8386
({ cutoutId }) => cutoutId === cutoutIdForAddressableArea
8487
)
88+
// what addressable areas we've already looped through and added to this cutout
8589
const previousRequiredAAs = acc[accIndex]?.requiredAddressableAreas
90+
91+
// what addressable area we're currently looking at and need to incorporate
8692
const allNextRequiredAddressableAreas =
8793
previousRequiredAAs != null &&
8894
previousRequiredAAs.includes(addressableArea)
8995
? previousRequiredAAs
9096
: [...previousRequiredAAs, addressableArea]
9197

98+
// check for the next compatible fixture for the new, longer list of addressable areas
9299
const nextCompatibleCutoutFixture = getSimplestFixtureForAddressableAreas(
93100
cutoutIdForAddressableArea,
94101
allNextRequiredAddressableAreas,
95102
cutoutFixturesForCutoutId
96103
)
97-
const indexOfCurrentFixture = cutoutFixturesForCutoutId.findIndex(
98-
({ id }) => id === nextCompatibleCutoutFixture?.id
99-
)
100104

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) {
105108
return [
106109
...acc.slice(0, accIndex),
107110
{
@@ -187,20 +190,14 @@ export function getSimplestFixtureForAddressableAreas(
187190
cutoutId,
188191
allCutoutFixtures
189192
)
193+
190194
const nextCompatibleCutoutFixtures = getCutoutFixturesForAddressableAreas(
191195
requiredAddressableAreas,
192196
cutoutFixturesForCutoutId
193197
)
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
206203
}

0 commit comments

Comments
 (0)