Waypoint inconsistency

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

Moderators: roger, gloomyandy, skoehler

breakbeatkid
New User
Posts: 2
Joined: Wed Nov 01, 2017 6:44 am

Waypoint inconsistency

Postby breakbeatkid » Wed Nov 01, 2017 4:22 pm

Hey, Im new here, please be kind! :D

Is there anyone that can shed some light on a problem I'm having with the navigator class and waypoints?

Code: Select all

import lejos.hardware.Brick;
import lejos.hardware.BrickFinder;
import lejos.hardware.Button;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.robotics.chassis.Chassis;
import lejos.robotics.chassis.Wheel;
import lejos.robotics.chassis.WheeledChassis;
import lejos.robotics.navigation.MovePilot;
import lejos.robotics.navigation.Navigator;

public class Waypoints {
   public static void main(String[] args) {
      Brick ev3 = BrickFinder.getDefault();

      //Set up pilot
      EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(ev3.getPort("B"));
      EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(ev3.getPort("C"));

      Wheel leftWheel = WheeledChassis.modelWheel(leftMotor, 3.3).offset(-10.3);
      Wheel rightWheel = WheeledChassis.modelWheel(rightMotor, 3.3).offset(10.3);
      Chassis myChassis = new WheeledChassis( new Wheel[]{leftWheel, rightWheel}, WheeledChassis.TYPE_DIFFERENTIAL);

      MovePilot pilot = new MovePilot(myChassis);
      Navigator navigator = new Navigator(pilot);
      
      String msg = "Enter to start...";

      System.out.println(msg);
      Button.waitForAnyPress();
      
      navigator.addWaypoint(40, 0);
      navigator.addWaypoint(40, 40);
      navigator.addWaypoint(0, 40);
      navigator.addWaypoint(0, 0);

      navigator.singleStep(true);
      
      while (!navigator.pathCompleted()) {            
         
         if(!navigator.isMoving()) {
            
            msg = "[" + navigator.getPoseProvider().getPose().getX() + ", " + navigator.getPoseProvider().getPose().getY() + "]\n";
            System.out.println(msg);
            
//            Button.waitForAnyPress();
            navigator.followPath();
         }
      }
      
      msg = "[" + navigator.getPoseProvider().getPose().getX() + ", " + navigator.getPoseProvider().getPose().getY() + "]";
      System.out.println(msg);
      
      
      msg = "Any key to finish...";
      System.out.println(msg);
      Button.waitForAnyPress();

   }
}


The issue i'm encountering is that there is no consistency across multiple executions of this code on my EV3. Some times it finishes close enough to be ok, but sometimes it turns to a random degree at different waypoints and sometimes it travels a random distance in the wrong direction. I'm at my wits end and deadlines are FAST approaching :(

It appears to be the same issue as was stated in this thread, but I can't see a clear solution in the whole post:
https://lejos.sourceforge.io/forum/viewtopic.php?f=18&t=7528

Correct (ish) outcome:
https://youtu.be/AfdU5hdKW0I

Randomly turns the wrong direction and gets lost:
https://youtu.be/Ww6F8EY_X4o

Any suggestions?

breakbeatkid
New User
Posts: 2
Joined: Wed Nov 01, 2017 6:44 am

Re: Waypoint inconsistency

Postby breakbeatkid » Wed Nov 01, 2017 6:58 pm

Using:

Code: Select all

Navigator navigator = new Navigator(pilot, myChassis.getPoseProvider());

appears to have fixed it!

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

Re: Waypoint inconsistency

Postby gloomyandy » Wed Nov 01, 2017 9:35 pm

Yes it seems there is a threading problem when using the standard pose provider that uses move notifications. The alternative pose provider (that monitors odometry), seemd to work fine. You can see the discussion of the bug here:
viewtopic.php?f=18&t=7528&start=45#p32293

I don't think any fix has been made for this bug, so what you are doing is the current way to work around it.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest