Correct me if I am wrong on this one but the travel() method in class SimpleNavigator
doesn't make the motors go backwards when dist is negative.
This happens because at left.rotate(-counts); right.rotate(-counts);
"counts" is already negative, so it becomes positive again!!!
- Code: Select all
public void travel(int dist) {
int counts = (int)(dist * COUNTS_PER_CM);
left.resetTachoCount();
right.resetTachoCount();
if(dist > 0) {
left.rotate(counts);
right.rotate(counts);
} else
if(dist < 0) {
left.rotate(-counts);
right.rotate(-counts);
}
while (left.isRotating() || right.isRotating());
moving = true;
stop();
}
I tried out the following version of travel() and works fine
(given that COUNTS_PER_CM is always positive) :
- Code: Select all
public void travel(int dist) {
int counts = (int)(dist * COUNTS_PER_CM);
left.resetTachoCount();
right.resetTachoCount();
left.rotate(counts);
right.rotate(counts);
while (left.isRotating() || right.isRotating());
moving=true;
stop();
}
Am I right? ...or have I just caused more problems?

