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

refactor(app): add move, positions, and disengage calls to robot-controls #4651

Merged
merged 1 commit into from
Dec 23, 2019
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
1 change: 1 addition & 0 deletions app/src/robot-controls/__fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

export * from './lights'
export * from './home'
export * from './move'
101 changes: 101 additions & 0 deletions app/src/robot-controls/__fixtures__/move.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// @flow

import { mockRobot } from '../../robot-api/__fixtures__'

// POST /robot/move

export const mockMoveSuccessMeta = {
method: 'POST',
path: '/robot/move',
ok: true,
status: 200,
}

export const mockMoveSuccess = {
...mockMoveSuccessMeta,
host: mockRobot,
body: { message: 'Move complete. New position: [1, 2, 3]' },
}

export const mockMoveFailureMeta = {
method: 'POST',
path: '/robot/move',
ok: false,
status: 500,
}

export const mockMoveFailure = {
...mockMoveFailureMeta,
host: mockRobot,
body: { message: 'AH' },
}

// GET /robot/positions

export const mockPositions = {
change_pipette: {
target: 'mount',
left: [325, 40, 30],
right: [65, 40, 30],
},
attach_tip: {
target: 'pipette',
point: [200, 90, 150],
},
}

export const mockFetchPositionsSuccessMeta = {
method: 'GET',
path: '/robot/positions',
ok: true,
status: 200,
}

export const mockFetchPositionsSuccess = {
...mockFetchPositionsSuccessMeta,
host: mockRobot,
body: {
positions: mockPositions,
},
}

export const mockFetchPositionsFailureMeta = {
method: 'GET',
path: '/robot/positions',
ok: false,
status: 500,
}

export const mockFetchPositionsFailure = {
...mockFetchPositionsFailureMeta,
host: mockRobot,
body: { message: 'AH' },
}

// POST /motors/disengage

export const mockDisengageMotorsSuccessMeta = {
method: 'POST',
path: '/motors/disengage',
ok: true,
status: 200,
}

export const mockDisengageMotorsSuccess = {
...mockDisengageMotorsSuccessMeta,
host: mockRobot,
body: { message: 'Disengaged axes: [a, b, c, x, y, z]' },
}

export const mockDisengageMotorsFailureMeta = {
method: 'POST',
path: '/motors/disengage',
ok: false,
status: 500,
}

export const mockDisengageMotorsFailure = {
...mockDisengageMotorsFailureMeta,
host: mockRobot,
body: { message: 'AH' },
}
35 changes: 35 additions & 0 deletions app/src/robot-controls/__tests__/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,41 @@ const SPECS: Array<ActionSpec> = [
meta: { requestId: 'abc' },
},
},
{
name: 'robotControls:MOVE',
creator: Actions.move,
args: ['robot-name', 'changePipette', 'left', true],
expected: {
type: 'robotControls:MOVE',
payload: {
robotName: 'robot-name',
position: 'changePipette',
mount: 'left',
disengageMotors: true,
},
meta: {},
},
},
{
name: 'robotControls:MOVE_SUCCESS',
creator: Actions.moveSuccess,
args: ['robot-name', { requestId: 'abc' }],
expected: {
type: 'robotControls:MOVE_SUCCESS',
payload: { robotName: 'robot-name' },
meta: { requestId: 'abc' },
},
},
{
name: 'robotControls:MOVE_FAILURE',
creator: Actions.moveFailure,
args: ['robot-name', { message: 'AH' }, { requestId: 'abc' }],
expected: {
type: 'robotControls:MOVE_FAILURE',
payload: { robotName: 'robot-name', error: { message: 'AH' } },
meta: { requestId: 'abc' },
},
},
{
name: 'robotControls:CLEAR_MOVEMENT_STATUS',
creator: Actions.clearMovementStatus,
Expand Down
41 changes: 39 additions & 2 deletions app/src/robot-controls/__tests__/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,44 @@ const SPECS: Array<ReducerSpec> = [
},
state: { robotName: { movementStatus: 'homing' } },
expected: {
robotName: { movementStatus: 'home-error', movementError: 'AH' },
robotName: { movementStatus: 'homeError', movementError: 'AH' },
},
},
{
name: 'handles robotControls:MOVE',
action: {
type: 'robotControls:MOVE',
payload: {
robotName: 'robotName',
position: 'attachTip',
mount: 'left',
disengageMotors: false,
},
meta: {},
},
state: { robotName: { movementStatus: null } },
expected: { robotName: { movementStatus: 'moving', movementError: null } },
},
{
name: 'handles robotControls:MOVE_SUCCESS',
action: {
type: 'robotControls:MOVE_SUCCESS',
payload: { robotName: 'robotName' },
meta: {},
},
state: { robotName: { movementStatus: 'moving' } },
expected: { robotName: { movementStatus: null, movementError: null } },
},
{
name: 'handles robotControls:MOVE_FAILURE',
action: {
type: 'robotControls:MOVE_FAILURE',
payload: { robotName: 'robotName', error: { message: 'AH' } },
meta: {},
},
state: { robotName: { movementStatus: 'moving' } },
expected: {
robotName: { movementStatus: 'moveError', movementError: 'AH' },
},
},
{
Expand All @@ -76,7 +113,7 @@ const SPECS: Array<ReducerSpec> = [
type: 'robotControls:CLEAR_MOVEMENT_STATUS',
payload: { robotName: 'robotName' },
},
state: { robotName: { movementStatus: 'home-error', movementError: 'AH' } },
state: { robotName: { movementStatus: 'homeError', movementError: 'AH' } },
expected: {
robotName: { movementStatus: null, movementError: null },
},
Expand Down
30 changes: 30 additions & 0 deletions app/src/robot-controls/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ export const homeFailure = (
meta,
})

export const move = (
robotName: string,
position: Types.MovePosition,
mount: Mount,
disengageMotors: boolean = false
): Types.MoveAction => ({
type: Constants.MOVE,
payload: { robotName, mount, position, disengageMotors },
meta: {},
})

export const moveSuccess = (
robotName: string,
meta: RobotApiRequestMeta
): Types.MoveSuccessAction => ({
type: Constants.MOVE_SUCCESS,
payload: { robotName },
meta,
})

export const moveFailure = (
robotName: string,
error: {| message: string |},
meta: RobotApiRequestMeta
): Types.MoveFailureAction => ({
type: Constants.MOVE_FAILURE,
payload: { robotName, error },
meta,
})

export const clearMovementStatus = (
robotName: string
): Types.ClearMovementStatusAction => ({
Expand Down
22 changes: 19 additions & 3 deletions app/src/robot-controls/constants.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
// @flow

// homing targets
// homing and move request targets

export const ROBOT: 'robot' = 'robot'
export const PIPETTE: 'pipette' = 'pipette'
export const MOUNT = 'mount'

// movement statuses

export const HOMING: 'homing' = 'homing'
export const HOME_ERROR: 'home-error' = 'home-error'
export const HOME_ERROR: 'homeError' = 'homeError'
export const MOVING: 'moving' = 'moving'
export const MOVE_ERROR: 'move-error' = 'move-error'
export const MOVE_ERROR: 'moveError' = 'moveError'

// move positions
export const CHANGE_PIPETTE: 'changePipette' = 'changePipette'
export const ATTACH_TIP: 'attachTip' = 'attachTip'

// http paths

export const LIGHTS_PATH: '/robot/lights' = '/robot/lights'
export const HOME_PATH: '/robot/home' = '/robot/home'
export const POSITIONS_PATH: '/robot/positions' = '/robot/positions'
export const MOVE_PATH: '/robot/move' = '/robot/move'
export const DISENGAGE_MOTORS_PATH: '/motors/disengage' = '/motors/disengage'

// action type strings

Expand Down Expand Up @@ -45,5 +53,13 @@ export const HOME_SUCCESS: 'robotControls:HOME_SUCCESS' =
export const HOME_FAILURE: 'robotControls:HOME_FAILURE' =
'robotControls:HOME_FAILURE'

export const MOVE: 'robotControls:MOVE' = 'robotControls:MOVE'

export const MOVE_SUCCESS: 'robotControls:MOVE_SUCCESS' =
'robotControls:MOVE_SUCCESS'

export const MOVE_FAILURE: 'robotControls:MOVE_FAILURE' =
'robotControls:MOVE_FAILURE'

export const CLEAR_MOVEMENT_STATUS: 'robotControls:CLEAR_MOVEMENT_STATUS' =
'robotControls:CLEAR_MOVEMENT_STATUS'
Loading