Code: Select all
MovePilot pilot = new MovePilot(getChassis());
pilot.addMoveListener(this);
Navigator navigator = new Navigator(pilot);
navigator.goTo(100,0);
navigator.waitForStop();
With the following listeners
Code: Select all
@Override
public void moveStopped(Move move, MoveProvider moveProvider) {
sendLogMessage("Stopped " + move.toString());
}
@Override
public void moveStarted(Move move, MoveProvider moveProvider) {
sendLogMessage("Started " + move.toString());
}
should and might return
Started ROTATE 0.0 at 284.9272
Stopped STOP
Started TRAVEL 100.0 at 409.7684
Stopped TRAVEL 99.51518 at 409.7684
but it will often return
Started ROTATE 0.0 at 284.9272
Stopped STOP
Started TRAVEL 100.0 at 409.7684
or even worse
Started ROTATE 0.0 at 284.9272
Started TRAVEL 100.0 at 409.7684
I believe the cause for this is because the Nav Thread in the Navigator and the Monitor Thread in the MovePilot don't interact properly.
The Nav Thread
-Checks whether the robot is stopped
-If it is it starts the next move
-Starting the next move calls the moveStarted listeners.
The Monitor Thread
-Checks whether the robot is stopped
-If it is it calls the moveStopped listeners.
Therefor when the robot stops moving there are two options.
1. The MovePilot finds out first and calls the moveStopped listeners. Then the Nav Thread finds out and starts the next move + calls the started listeners.
2. The Nav Thread finds out first and starts the next move (which calls the moveStarted listeners). The Monitor thread in the MovePilot never realizes the move stopped and never calls the moveStopped listeners.
How can I make option 1 always happen and never option 2?
For a bit of background I am making a Custom Pose Provider and I need to know precisely when the moves start and finish. I also believe this bug can cause faulty readings to the odometry pose provider (see its source code).