Skip to content

Commit

Permalink
Add motor control translation
Browse files Browse the repository at this point in the history
This takes the differential steering values and maps them to motor commands
  • Loading branch information
dlindahl committed Jul 19, 2016
1 parent c4d25af commit 0d29478
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/motor_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var diffSteer = require('./diff_steer');

function explicate(motorSpeed) {
leftMotorDirection = motorSpeed > 0 ? motorControl.revMethod : motorControl.fwdMethod;
leftMotorSpeed = Math.abs(motorSpeed);
return [leftMotorDirection, leftMotorSpeed];
}

function motorControl(wheels, leftRightAxis, upDownAxis, maxAxis, minAxis, maxSpeed, axisFlip) {
var leftMotor;
var leftMotorDirection;
var leftMotorSpeed = 0;
var motorSpeeds;
var rightMotor;
var rightMotorDirection;
var rightMotorSpeed = 0;

// Map differential steering values to motor commands
motorSpeeds = diffSteer(leftRightAxis, upDownAxis, maxAxis, minAxis, maxSpeed, axisFlip);
leftMotor = explicate(motorSpeeds[0]);
leftMotorDirection = leftMotor[0];
leftMotorSpeed = leftMotor[1];
rightMotor = explicate(motorSpeeds[1]);
rightMotorDirection = rightMotor[0];
rightMotorSpeed = rightMotor[1];

wheels[0][leftMotorDirection](leftMotorSpeed);
wheels[1][rightMotorDirection](rightMotorSpeed);

return [
{
direction: leftMotorDirection,
speed: leftMotorSpeed
},
{
direction: rightMotorDirection,
speed: rightMotorSpeed
}
];
}
motorControl.fwdMethod = 'fwd';
motorControl.revMethod = 'rev';

module.exports = motorControl;
1 change: 1 addition & 0 deletions motor_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/motor_control');

0 comments on commit 0d29478

Please sign in to comment.