lejos pathfinding

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

Moderators: roger, 99jonathan, imaqine

lejos pathfinding

Postby zlttaw » Thu Oct 18, 2012 1:14 pm

Hi all,

I am pretty new to lejos class but currently i wanted to do some navigation on a grid map in which the robot is only allowed to move up,down,left and right while following a black line.


From the lejos api, I found classes like lineMap, fourwaygridmesh, astar algorithm, pathfinder and so on. I think if i implement all this together would get the result i want however the documentations or examples for all this is quite limited.

I just want to know how can i implement all this together?

Here is what i found out so far, in order to use fourwaygrid mesh i would need a linemap.

If my map is a gridmap, How should i implement linemap for such a scenario?

For the path, I would want to be able to set the starting point and ending point and the algorithm would help to calculate the shortest path to the ending point. How should i combine everything together?

This are the codes i have so far, can someone advise on what i need to do to implement the grid map?
Code: Select all
lejos.geom.Rectangle bounds = new Rectangle(50, 60, 300, 300);
   LineMap myMap = new LineMap(lines, bounds);
   FourWayGridMesh grid = new FourWayGridMesh(myMap, 50, 0);
        AstarSearchAlgorithm alg = new AstarSearchAlgorithm();
   NodePathFinder pf = new NodePathFinder(alg,grid);



Thanks in advance.
zlttaw
New User
 
Posts: 1
Joined: Thu Oct 18, 2012 12:54 pm

Re: lejos pathfinding

Postby Mikee_ITguy » Tue Dec 18, 2012 9:02 pm

Hi zlttaw,

I am also strugling to make a navigator working, from what I understand I can say this:

You need a line map which is made of lines and some boundaries (if I get this right)
so I am trying to make robot move on a rectangle map, so myMap is like this:
Code: Select all
         Line [] lines = new Line[3];
         
         lines [0] = new Line(2, 2, 38, 2);   //left >> right
         lines [1] = new Line(38, 2, 38, 78);      // down >> up
         lines [2] = new Line(38, 78, 2, 78);
      
         lejos.geom.Rectangle bounds = new Rectangle(0, 0, 50, 90);

          this.myMap = new LineMap(lines, bounds);
   


After you create a map you need to create on the map nodes (kinda points which the robot will connect to make path to destination) by using the FourWayGridMesh. That should make a grid of certain size with some spacing between. After that you need something to find the path through the grid, that would be some pathfinder using searching algorithm (I am using A*) and then just wrap it all together:

Code: Select all
         // Use a regular grid of node points. Grid space = 15. Clearance = 10:
         FourWayGridMesh grid = new FourWayGridMesh(myMap, 15, 10);

         // Use A* search:
         AstarSearchAlgorithm alg = new AstarSearchAlgorithm();
         
         // Give the A* search alg and grid to the PathFinder:
         this.pf = new NodePathFinder(alg, grid);   


afterwards you just create navigator using all above:

Code: Select all
   PoseProvider position = new OdometryPoseProvider(robot);
                   
                   Navigator nav = new Navigator(robot, position) ;
                   System.out.println("Planning path...");
                   nav.followPath(pf.findRoute(position.getPose(), new Waypoint(20, 40)));
                   nav.waitForStop();
         


Now that is IN THEORY how it should work, as I said I am strugling with navigator for last week and half and still he doesn't work for me correctly.

EDIT: If you are getting destination unreachable error look here http://lejos.sourceforge.net/forum/viewtopic.php?f=7&t=3223, Roger explained it well there.

I hope it puts some light on the navigator for you
Mikee_ITguy
New User
 
Posts: 12
Joined: Sat Aug 25, 2012 12:50 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff