-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import test from 'ava'; | ||
import diffSteer from '../index'; | ||
import INPUTS from './inputs'; | ||
|
||
test('Full forward', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.FULL_FWD); | ||
t.is(motorSpeeds[0], 255); | ||
t.is(motorSpeeds[1], 255); | ||
}); | ||
|
||
test('Full reverse', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.FULL_REV); | ||
t.is(motorSpeeds[0], -255); | ||
t.is(motorSpeeds[1], -255); | ||
}); | ||
|
||
test('Full right', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.FULL_RIGHT); | ||
t.is(motorSpeeds[0], 255); | ||
t.is(motorSpeeds[1], -255); | ||
}); | ||
|
||
test('Full left', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.FULL_LEFT); | ||
t.is(motorSpeeds[0], -255); | ||
t.is(motorSpeeds[1], 255); | ||
}); | ||
|
||
test('Forward right', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.FWD_RIGHT); | ||
t.is(motorSpeeds[0], 255); | ||
t.is(motorSpeeds[1], -6.000150000000013); | ||
}); | ||
|
||
test('Reverse left', t => { | ||
t.plan(2); | ||
const motorSpeeds = diffSteer(...INPUTS.REV_LEFT); | ||
t.is(motorSpeeds[0], -105.88978213646999); | ||
t.is(motorSpeeds[1], -196.940063931765); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
FULL_FWD: [0, -1], | ||
FULL_RIGHT: [1, 0], | ||
FULL_LEFT: [-1, 0], | ||
FULL_REV: [0, 1], | ||
FWD_RIGHT: [0.764706, -0.741176], | ||
REV_LEFT: [-0.726881, 0.686763] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import INPUTS from './inputs'; | ||
import steerMotor from '../motor_control'; | ||
import sinon from 'sinon'; | ||
import test from 'ava'; | ||
|
||
test.beforeEach(t => { | ||
t.context.leftMotor = { | ||
fwd: sinon.stub(), | ||
rev: sinon.stub() | ||
}; | ||
t.context.rightMotor = { | ||
fwd: sinon.stub(), | ||
rev: sinon.stub() | ||
}; | ||
t.context.wheels = [t.context.leftMotor, t.context.rightMotor]; | ||
}); | ||
|
||
test('Full forward', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.FULL_FWD); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'fwd'); | ||
t.is(motorCommands[0].speed, 255); | ||
t.true(t.context.leftMotor.fwd.calledWith(255)); | ||
t.is(motorCommands[1].direction, 'fwd'); | ||
t.is(motorCommands[1].speed, 255); | ||
t.true(t.context.rightMotor.fwd.calledWith(255)); | ||
}); | ||
|
||
test('Full reverse', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.FULL_REV); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'rev'); | ||
t.is(motorCommands[0].speed, 255); | ||
t.true(t.context.leftMotor.rev.calledWith(255)); | ||
t.is(motorCommands[1].direction, 'rev'); | ||
t.is(motorCommands[1].speed, 255); | ||
t.true(t.context.rightMotor.rev.calledWith(255)); | ||
}); | ||
|
||
test('Full right', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.FULL_RIGHT); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'fwd'); | ||
t.is(motorCommands[0].speed, 255); | ||
t.true(t.context.leftMotor.fwd.calledWith(255)); | ||
t.is(motorCommands[1].direction, 'rev'); | ||
t.is(motorCommands[1].speed, 255); | ||
t.true(t.context.rightMotor.rev.calledWith(255)); | ||
}); | ||
|
||
test('Full left', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.FULL_LEFT); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'rev'); | ||
t.is(motorCommands[0].speed, 255); | ||
t.true(t.context.leftMotor.rev.calledWith(255)); | ||
t.is(motorCommands[1].direction, 'fwd'); | ||
t.is(motorCommands[1].speed, 255); | ||
t.true(t.context.rightMotor.fwd.calledWith(255)); | ||
}); | ||
|
||
test('Forward right', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.FWD_RIGHT); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'fwd'); | ||
t.is(motorCommands[0].speed, 255); | ||
t.true(t.context.leftMotor.fwd.calledWith(255)); | ||
t.is(motorCommands[1].direction, 'rev'); | ||
t.is(motorCommands[1].speed, 6.000150000000013); | ||
t.true(t.context.rightMotor.rev.calledWith(6.000150000000013)); | ||
}); | ||
|
||
test('Reverse left', t => { | ||
const motorCommands = steerMotor(t.context.wheels, ...INPUTS.REV_LEFT); | ||
t.plan(6); | ||
t.is(motorCommands[0].direction, 'rev'); | ||
t.is(motorCommands[0].speed, 105.88978213646999); | ||
t.true(t.context.leftMotor.rev.calledWith(105.88978213646999)); | ||
t.is(motorCommands[1].direction, 'rev'); | ||
t.is(motorCommands[1].speed, 196.940063931765); | ||
t.true(t.context.rightMotor.rev.calledWith(196.940063931765)); | ||
}); |