Bug : moveStarted called before moveStopped with Navigator

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

SUPERETDUPER
New User
Posts: 15
Joined: Sat Apr 15, 2017 8:52 pm

Bug : moveStarted called before moveStopped with Navigator

Postby SUPERETDUPER » Wed Jan 31, 2018 3:13 pm

The following piece of code

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).

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bug : moveStarted called before moveStopped with Navigator

Postby gloomyandy » Wed Jan 31, 2018 3:41 pm

Yep this is a sort of known issue. See the discussion in this thread...
viewtopic.php?f=18&t=7528&start=45
and this one...
viewtopic.php?f=18&t=9091

As you can see I proposed a possible fix, but I'm not aware of anyone trying it. To be honest the entire listener mechanism is not great. I'd be very cautious of writing any sort of code that required "to know precisely when the moves start and finish". Not sure what it is you are trying to do, but if you using the MovePilot/Chassis then the PoseProvider thet is built in works very well and will operate when using moves that use continuous motion (rather than simple stop/start) and that do not fit the forward/back/rotate model.
leJOS news https://lejosnews.wordpress.com/

SUPERETDUPER
New User
Posts: 15
Joined: Sat Apr 15, 2017 8:52 pm

Re: Bug : moveStarted called before moveStopped with Navigator

Postby SUPERETDUPER » Wed Jan 31, 2018 9:12 pm

Ok thanks! I had also spotted the isMoving() method in the pilot as a possible fix. I think this would work.

SUPERETDUPER
New User
Posts: 15
Joined: Sat Apr 15, 2017 8:52 pm

Re: Bug : moveStarted called before moveStopped with Navigator

Postby SUPERETDUPER » Sat Feb 03, 2018 11:39 pm

I tried changing the isMoving() and it seems to have solved the problem! Thanks! I had to copy the source code into my own class to modify it. What is the license for the project? Can I do this? Do I need to reference some author? Thanks!

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Bug : moveStarted called before moveStopped with Navigator

Postby gloomyandy » Sun Feb 04, 2018 8:27 am

Licensing for leJOS is a bit of a mess. It is basically GPL, but don't worry about it.So long as you are not planning on selling it for a fortune I doubt if anyone will be very concerned. Just make sure you acknowledge the leJOS project and its authors if you publish anything.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest