Saturday, February 24, 2018

GPSd Java and the Raspberry Pi

GPSd Java and the Raspberry Pi


The float for RoboGoby will have a Global Positioning System, or GPS, onboard for real-time tracking. GPSs are readily available and extremely easy to interface into your project. There are various different GPS module from Sparkfun, Adafruit, Mouser, and other distributors. They come with different antennas, although a custom fit ceramic antenna is the most common.

Ceramic antenna

GPSs also come with different update rates (in Hz) and different channels. Channels represent the number of satellites a receiver can receive data from at the same time. And Hz, or hertz, is the speed of your module. If youre not sure which GPS is right for your project, check out SparkFuns GPS Buying Guide. 

The awesome thing about GPS receivers is that soon after they receive power, they continuously output a string of ASCII characters through a serial cable/UART connection. The string contains coordinates, altitude, time, speed, directional degrees, etc.  In order to read the data from a GPS you need to download a GPS parser which can decode the GPS ASCII and then implement in your code (in our case a simple Java program). 

We are currently using a pre-constructed USB GPS (image below -- you can see the ceramic antenna inside). Other GPSs (like the Ultimate GPS from Adafruit) can be wired to an Arduino or Pi using UART (more info found here).


USB GPS Reciever




To test the GPS, we used a generic python setup from Adafruit (found here). The following quick steps make sure the GPS is working (our USB GPS was located on /dev/ttyUSB0). After making sure the GPS is working, you can add the python code, gps.txt file, and Java code we used to read the GPS data (we had to write the data to a file using python and then read it using Java. Although this means switching platforms it is ten-fold easier than using Java directly -- trust us, we tried).


If you type in the following you will see a bunch of unknown characters. This is because the Pi cannot decipher the ASCII strings. Youll need to download GPSd to do that.




1. Download GPSd and the python library needed to read GPS data:




2. Tell GPSd where to look on the Pi for the data stream (in our case /dev/ttyUSB0)




3. Make sure that your GPS is using GPSd and receiving data from your module:

GPS Data


...and using the same cat command above you now see recognizable data (somewhat recognizable...)!




The next step is parsing the data into a usable form. For this, we are going to use Java. (make sure you have Java installed ---> sudo apt-get install openjdk-7-jre). The Java code will read the data written to a text file using Python. The python code uses the TPV-Class to read the lat and lon data (check out the link for the full set of data available using TPV).

All of the code can be found in the GPS folder located on our download site. Below is a quick explanation of what the code does.

1. The python code (gpsPi.py) reads the data from the GPS and parses it into recognizable latitude and longitude values. It then writes this data to gps.txt and then immediately runs gps.jar. The Java file (gps.jar) reads the data from gps.txt and converts it into a DD�MM.MSS.SSS" format. Pictures of the code are below:

***do not name your python file gps.py as the method it uses to call the GPS module will NOT work.


gpsPi.py

gps.jar



�and this is the data output on the Pi!




To make sure your coordinates are correct check out this sweet website.


visit link download