SimpleNavigator goTo() Problem

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

SimpleNavigator goTo() Problem

Postby Cyber » Mon Jul 20, 2009 4:40 pm

Hi all!
I´ve got a big Problem by using the goTo Method for a SimpleNavigator.
The problem is, that the robot don´t goes the way he should.
When i use the Points the robot moves not the same way as when i insert the values manually like the uncommented lines.
Can someone tell why he do this an how i can solve this problem?
Its very important because im just writing my bachelor paper over nxj programming.
Code: Select all
      Point a,b,c;
      a = new Point(10,0); b = new Point(20,0); c = new Point(20,10);
      System.out.println(tn.getX() + " " + tn.getY());
      Button.waitForPress();
//      tn.goTo(10, 0);
      tn.goTo(a.x, a.y);
      System.out.println(tn.getX() + " " + tn.getY());
      Button.waitForPress();
//      tn.goTo(20, 0);
      tn.goTo(b.y,b.y);
      System.out.println(tn.getX() + " " + tn.getY());
      Button.waitForPress();
//      tn.goTo(20, 10);
      tn.goTo(c.x,c.y);
      System.out.println(tn.getX() + " " + tn.getY());
      Button.waitForPress();
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby Cyber » Mon Jul 20, 2009 4:45 pm

Can someone move this Thread to "NXJ Software"? :) Sorry for the wrong Forum.
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby lawrie » Mon Jul 20, 2009 9:36 pm

Where are you getting the implementation of Point from?
What import statement are you using? leJOS 0.8 does not include java.awt.Point (but there is a version in lejos.localization).

Repost the message if you want it moved.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby Cyber » Mon Jul 20, 2009 9:51 pm

I´m using the Point from lejos.localization.Point.

Its really crazy. The movement now works but there is still a problem with it.

I´m calculating a optimal path through a scenario by using an implementation of the a* algorithm.
The result is stored in an arraylist of points but this dont work. the roboter moves but not as he should.

Code: Select all
      ArrayList<Point> al = new ArrayList<Point>();
      al.add(a);
      al.add(b);
      al.add(c);

      while (true) {
         for (int i = 0; i < al.size(); i++) {
            try {
               m = al.get(i);
               System.out.println(tn.getX() + " " + tn.getY());
               tn.goTo(m.x, m.y);
               System.out.println(m.x + " " + m.y);
               al.remove(i);
            } catch (Exception e) {

            }
         }
      }


This is how it looks atm but later i want to use an own implementation of a stack because ich need a generic stack. the path a* returns a generic stack of points.
very funny. when i go through it an draw the points on the lcd, they where shown up correctly.
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby lawrie » Mon Jul 20, 2009 10:04 pm

You use of ArrayLists looks wrong. Removing element i will shuffle the others down and you will skip some of the points. Trying commenting out the remove.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby Cyber » Tue Jul 21, 2009 8:42 am

Ok i´ll test it but i don´t think thats the problem.

Don´t work. I think i have to start at the beginning =) because i can´t get him to drive a simple square on the ground.

Can someone tell me where my fault is? I think i somewhere have a error in reasoning (Denkfehler).

The following code should let him drive a square or not? and how does the robot knows his view? (e.g. standing at pos 10,10 and the front shows to the y axis or is there a default value.)
Code: Select all
SimpleNavigator tn = new SimpleNavigator(5.6f, 11.5f, Motor.A,
            Motor.C);

      tn.setPosition(10, 10, 0);
      tn.goTo(10, -10 );
      tn.goTo(-10, -10 );
      tn.goTo(-10, 10 );
      tn.goTo(10, 10 );
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby Cyber » Tue Jul 21, 2009 11:30 am

Another Example.
Code: Select all
      tn.setPosition(0, 0, 0);
      tn.goTo(10, 0);
      tn.goTo(5, 0);
      tn.goTo(15, 0);


This code should move the robot from (0,0) to (10,0) along x axis. - works
Then he turns 180 degree around and moves to (5,0). -works
Now he should turn again 180 degree and go to (15,0). -dont works

I dont understand why not... :roll:
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby pEhrlich » Tue Jul 21, 2009 11:55 am

Unfortunately I don't have a robot on my, or i would test and confirm.

Now he should turn again 180 degree and go to (15,0). -dont works


what happens instead? anything?'

what happens is you start out with a -15, or change it to other numbers besides 15? Is it just the double turn that confuses it? Triple turn? etc?
User avatar
pEhrlich
Advanced Member
 
Posts: 158
Joined: Fri Jan 04, 2008 1:38 am

Postby Cyber » Tue Jul 21, 2009 12:00 pm

instead he travels to -10. it seems that he cant remember the turn but when i set the position to angle 0 or 180 the movement is still the same.

I think there is a bigger Problem maybe with the current firmeware. I tryed out a simple Program from the Book Maximum Lego NXT.

public class Simple {

public static void main(String[] args){

SimpleNavigator sNav = new SimpleNavigator (5.6f, 11.5f, Motor.A,
Motor.C);

sNav.goTo(50, 0);
sNav.goTo(25, 25);
sNav.goTo(25, -25);
sNav.goTo(0, 0);


And this also don´t work.

Is there anywhere an old version of lejos? 0.7 e.g. then i will try out if this works
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby Cyber » Tue Jul 21, 2009 1:08 pm

Ok so now i´ve tried version 0.7 and this works good with the sample code from the book.
but i can´t use it for my project because the arraylist in this version seems not to be generic :/ Also i can´t compile it. everytime an java.lang.byte not found error is thrown under 0.7.
someone an idea?
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany


Return to NXJ Projects

Who is online

Users browsing this forum: Google [Bot] and 1 guest

more stuff