Simple Navigator X,Y coordinates

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Simple Navigator X,Y coordinates

Postby westes » Thu Jul 23, 2009 9:03 pm

I wrote a program that uses SimpleNavigator to write X,Y cordinates to the screen. It stays at 0.0 instead of inclining. Heres my code:\
Code: Select all
import lejos.navigation.SimpleNavigator;

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;

public class NavTest {


   public static void main(String[] args)  {
      
      SimpleNavigator nav = new SimpleNavigator(5.6F,12.635F,Motor.B,Motor.A);
             
               nav.setSpeed(500);
               nav.forward();
               while(!Button.ENTER.isPressed()) {
                  float X = nav.getX();
                  float Y = nav.getX();
                  LCD.drawString("" + X ,0,0);
                  LCD.drawString("" + Y ,0,2);
               }
               
   }

}
westes
New User
 
Posts: 21
Joined: Wed Jul 22, 2009 12:38 am

Postby Cyber » Thu Jul 23, 2009 9:06 pm

hmm i think the updatePosition() is only called if you do nav.stop() so the new coordinates are not recognized.
but maybe i´m wrong =)
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby lawrie » Thu Jul 23, 2009 9:13 pm

Yes, that is true. If you call a method like forward or backward you need to call stop, before the position is updated. We don't currently have a navigator that continously updates the position.
lawrie
leJOS Team Member
 
Posts: 929
Joined: Mon Feb 05, 2007 1:27 pm

Postby westes » Thu Jul 23, 2009 9:15 pm

That seemed to do the trick. How did I miss that function in the documentation? :D
westes
New User
 
Posts: 21
Joined: Wed Jul 22, 2009 12:38 am

Postby Cyber » Thu Jul 23, 2009 9:16 pm

Don´t read the Documentation, read the Sources =)
Cyber
Novice
 
Posts: 27
Joined: Mon Jul 20, 2009 4:34 pm
Location: Germany

Postby westes » Fri Jul 24, 2009 3:50 pm

Yeah.
All I had to do is call the update position on the navigator. :D
Thanks again!
westes
New User
 
Posts: 21
Joined: Wed Jul 22, 2009 12:38 am


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff