GPS

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

Moderators: 99jonathan, roger, imaqine

GPS

Postby AndrejDelany » Sun May 29, 2011 4:32 pm

Hi,

I've a problem with the GPS functions in leJOS.

I want the device to connect with a Bluetooth GPS device, that works fine. But in most cases I get an "Exception: 16", somewhere after the println("Verbunden."). What does that mean?

The System has two Coordinates: koor and koor_aktuell. koor is the previous coordinate, koor_aktuell the current. In the while-part, the distance between these coordinates is added to "entfernung".

Here is my code:

Code: Select all

import.....

public class BLUBB {

   public static SimpleGPS gps = null;
   public static InputStream in = null;
   public static Coordinates koor, koor_aktuell;
   public static final byte[] pin = {(byte) '0', (byte) '0', (byte) '0', (byte) '0'};
   
   public static void main(String[] args) {
      
      System.out.println("Geraet-Suche...");
      
       RemoteDevice btrd = Bluetooth.getKnownDevice("B-Speech GPS2");
       if (btrd == null) {
          System.out.println("Kein Geraet gefunden.");
          Button.waitForPress();
          return;
       } else {
          System.out.println("Geraet gefunden.");
       }
      
       System.out.println();
       System.out.println("Verbinden...");
      
       BTConnection btGPS = Bluetooth.connect(btrd.getDeviceAddr(), NXTConnection.RAW, pin);

      
       if (btGPS == null) {
          System.out.println("Nicht verbunden.)");
          Button.waitForPress();
          return;
       } else {
          System.out.println("Verbunden.");
       }
      
       System.out.println();

       in = btGPS.openInputStream();
       gps = new GPS(in);
      
       double entfernung = 0;
       koor = new Coordinates(gps.getLatitude(), gps.getLongitude(), gps.getAltitude());
      
       int count = 0;
      
       while(true) {
          
             try{Thread.sleep(6000);}catch(Exception e) {}
             
             koor_aktuell = new Coordinates(gps.getLatitude(), gps.getLongitude(), gps.getAltitude()); 
            
             entfernung += koor_aktuell.distance(koor);
            
             System.out.println(count + ": " + entfernung);
             System.out.println();
            
             koor = koor_aktuell;
             count++;
   
       }
   }
}


Hopefully someone of you can help me.

Thanks, Andrej
AndrejDelany
New User
 
Posts: 2
Joined: Sun May 29, 2011 4:24 pm

Re: GPS

Postby gloomyandy » Sun May 29, 2011 4:49 pm

To work out what the exception codes mean and where they are occurring take a look at the FAQ:
viewtopic.php?f=7&t=236
and at the tutorial:
http://lejos.sourceforge.net/nxt/nxj/tu ... ugging.htm

Without running your actual code (with your GPS device) it is not possible for anyone to say what is going on, you will need to use the exception information to work out which part of the code the exception is being thrown from. Once you do that you may want to post back here with the details and we will try and help...

Oh and when asking for help please let us know which version of leJOS you are using etc... The more you tell us the more likely you are to get a useful response...

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

Re: GPS

Postby bbagnall » Tue May 31, 2011 2:13 pm

I recommend using the javax.microedition.location package. It is the standard Java method for connecting and using GPS. The API docs for this package shoudl explain pretty well how to use these packages and you should be able to find other explanations on the web since this is how standard Java apps access GPS.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Re: GPS

Postby Rickz2020 » Wed Jun 29, 2011 12:01 am

Do you get the exception when the bluetooth device is turned off while the program is executing? Perhaps it's when the bluetooth device gets out of range?

Do you know where the error is occurring? If not, try and print out messages on the screen where you think it might be going wrong - this way you can isolate what line is causing the error and from there it may be easier to solve.

Rich.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.

Re: GPS

Postby esmetaman » Wed Oct 12, 2011 4:11 pm

Hi everyone,

I tested the same examples that the user and we have to close this bug with GPS devices.
I receive the same problem.

Brian, I tested the examples: GPSInfo and BTGPS and I have some exceptions. I think that we have to debug it.
Did you have the same results?

Do you have an example to use that package?

javax.microedition.location package


Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: GPS

Postby esmetaman » Sun Oct 16, 2011 3:24 pm

Hi Andrej,

you have reason, our support for GPS is weak, but we found the source of problem.
In some cases, BT GPS receives return to NXT brick some values which our classes to manage GPS values is not ready.

we are working to update the package to solve this kind of situations.

Next week, the package will be updated with a better implementation more robust. Latest implementation was done in 2009 and few users used this area in the project.

Many thanks for the feedback.

I will inform when all classes are updated and tested again.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: GPS

Postby esmetaman » Sun Oct 30, 2011 3:30 pm

Hi Andrew,

recently, I did some changes to solve the problems.

Download code from SVN and use a snapshot to replace your current firmware and use classes from SVN in your eclipse project to test again the samples:

BTGPS
GPSInfo

I added a new sample LocationPTest to test the way that Brian said in previous post

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.iloveneutrinos.com/
User avatar
esmetaman
Advanced Member
 
Posts: 290
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff