Page 82 - The Definitive Guide to Building Java Robots
P. 82
Preston_5564C03.fm Page 63 Wednesday, October 5, 2005 7:21 AM
CHAPTER 3 ■ MOTION 63
// setting motor values
public void setMotors(int left, int right) {
this.left = left;
this.right = right;
}
// actually moving the motors
private void move() throws Exception {
// left wheel
ssc.move(LEFT_WHEEL, left);
// right wheel
ssc.move(RIGHT_WHEEL, right);
}
// move in reverse
public void reverse() throws Exception {
// if inverted move motors opposite or same.
if (motorsInverted) {
// opposite direction
setMotors(leftHigh, rightLow);
} else {
// same direction
setMotors(leftHigh, rightHigh);
}
// move motors
move();
}
// move forward
public void forward() throws Exception {
if (motorsInverted) {
setMotors(leftLow, rightHigh);
} else {
setMotors(leftLow, rightLow);
}
move();
}
// pivot on axis right
public void pivotRight() throws Exception {
if (motorsInverted) {
setMotors(leftLow, rightLow);
} else {
setMotors(leftLow, rightHigh);
}
move();
}