Skip to content

Commit

Permalink
feat(step-generation): python commands for disengage and engage magnet (
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored Mar 4, 2025
1 parent 9fee69e commit 6423013
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion step-generation/src/__tests__/disengageMagnet.test.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ describe('disengageMagnet', () => {
id: moduleId,
type: MAGNETIC_MODULE_TYPE,
model: MAGNETIC_MODULE_V1,
pythonName: 'mockPythonName',
pythonName: 'mock_magnetic_module_1',
}
robotState = getInitialRobotStateStandard(invariantContext)
robotState.modules[moduleId] = {
@@ -46,6 +46,7 @@ describe('disengageMagnet', () => {
},
},
],
python: 'mock_magnetic_module_1.disengage()',
})
})
})
3 changes: 2 additions & 1 deletion step-generation/src/__tests__/engageMagnet.test.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ describe('engageMagnet', () => {
id: moduleId,
type: MAGNETIC_MODULE_TYPE,
model: MAGNETIC_MODULE_V1,
pythonName: 'mockPythonName',
pythonName: 'mock_magnetic_module_1',
}
robotState = getInitialRobotStateStandard(invariantContext)
robotState.modules[moduleId] = {
@@ -49,6 +49,7 @@ describe('engageMagnet', () => {
},
},
],
python: `mock_magnetic_module_1.engage(height_from_base=${height})`,
})
})
})
9 changes: 7 additions & 2 deletions step-generation/src/commandCreators/atomic/disengageMagnet.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export const disengageMagnet: CommandCreator<ModuleOnlyParams> = (
prevRobotState
) => {
const { moduleId } = args
const { moduleEntities } = invariantContext
const commandType = 'magneticModule/disengage'

if (moduleId === null) {
@@ -21,9 +22,12 @@ export const disengageMagnet: CommandCreator<ModuleOnlyParams> = (
}

assert(
invariantContext.moduleEntities[moduleId]?.type === MAGNETIC_MODULE_TYPE,
`expected module ${moduleId} to be magdeck, got ${invariantContext.moduleEntities[moduleId]?.type}`
moduleEntities[moduleId]?.type === MAGNETIC_MODULE_TYPE,
`expected module ${moduleId} to be magdeck, got ${moduleEntities[moduleId]?.type}`
)

const pythonName = moduleEntities[moduleId].pythonName

return {
commands: [
{
@@ -34,5 +38,6 @@ export const disengageMagnet: CommandCreator<ModuleOnlyParams> = (
},
},
],
python: `${pythonName}.disengage()`,
}
}
9 changes: 7 additions & 2 deletions step-generation/src/commandCreators/atomic/engageMagnet.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export const engageMagnet: CommandCreator<EngageMagnetParams> = (
prevRobotState
) => {
const { moduleId, height } = args
const { moduleEntities } = invariantContext
const commandType = 'magneticModule/engage'

if (moduleId === null) {
@@ -21,9 +22,12 @@ export const engageMagnet: CommandCreator<EngageMagnetParams> = (
}

assert(
invariantContext.moduleEntities[moduleId]?.type === MAGNETIC_MODULE_TYPE,
`expected module ${moduleId} to be magdeck, got ${invariantContext.moduleEntities[moduleId]?.type}`
moduleEntities[moduleId]?.type === MAGNETIC_MODULE_TYPE,
`expected module ${moduleId} to be magdeck, got ${moduleEntities[moduleId]?.type}`
)

const pythonName = moduleEntities[moduleId].pythonName

return {
commands: [
{
@@ -35,5 +39,6 @@ export const engageMagnet: CommandCreator<EngageMagnetParams> = (
},
},
],
python: `${pythonName}.engage(height_from_base=${height})`,
}
}

0 comments on commit 6423013

Please sign in to comment.