Lab 7 – GPS

7. GPS

The Global Positioning System (GPS) is attractive for robots, but has disadvantages.

  • GPS is accurate enough to tell what street you are on, but not good enough to keep you in lane.
  • In cities, reflections from buildings can degrade accuracy.
  • GPS is not available indoors, in tunnels, or underpasses.

More expensive GPS receivers can be more accurate. The GPS satellite system network is currently being upgraded, and performance of low cost units should increase substantially in a few years.

The Elcano design uses GPS as a secondary navigation system that removes drift from the other sensors.

Basic GPS

The GPS hardware is Adafruit Ultimate GPS+Logging shield. Tutorial is on https://learn.adafruit.com/adafruit-ultimate-gps-logger-shield

Plug the shield into a Duemillenove, Mega, or Uno; the Leonardo will not work. Upload a simple program such as “blink” from examples. Set the switch to “Direct”. From Arduino IDE, select serial monitor, and set it to 9600 baud. You should then see the messages from the GPS receiver. If you are outdoors, or close to a window, these messages will give your location. If you have no access to the sky, the message content will be blank. The GPS uses its own serial input and output lines, which are distinct from the Arduino Rx and Tx. Setting the switch to “Direct” routes GPS output directly to the PC via USB, bypassing the Arduino. Example messages:

$GPRMC,170050.000,A,4740.2972,N,12218.6698,W,2.81,150.99,100614,,,A*72

$GPVTG,150.99,T,,M,2.81,N,5.21,K,A*34

$GPGGA,170051.000,4740.2966,N,12218.6694,W,1,8,1.15,67.0,M,-17.3,M,,*51

$GPGSA,A,3,13,07,23,10,16,08,20,03,,,,,1.47,1.15,0.90*07

$GPGSV,4,1,15,13,85,001,30,23,58,118,21,07,50,259,41,16,46,062,36*7F

$GPGSV,4,2,15,10,41,291,20,48,34,194,,08,28,250,31,30,21,251,19*79

$GPGSV,4,3,15,03,16,127,24,27,15,103,,20,12,178,16,02,06,299,19*79

$GPGSV,4,4,15,05,03,328,,04,02,260,,19,01,131,*4A

$GPRMC,170051.000,A,4740.2966,N,12218.6694,W,3.52,150.62,100614,,,A*71

To understand the messages, see NMEA Output Sentences in http://www.adafruit.com/datasheets/GlobalTop-FGPMMOPA6H-Datasheet-V0A.pdf

The example has messages for RMC (Recommended Minimum Navigation Information), VTG (Velocity Relative To Ground), GGA (System Fixed Data), GSA (Satellites Active and Dilution of Precision), and GSV (GNSS Satellites in View).

The first RMC message gives the location as (47° 40.2972′ N, 122° 18.6698′ W) and time as 17:00:50.000 (10:00 AM PDT). UTC date is 10 June 2014, which matches the local date. GPS time is more accurate than most other time sources, though you need to compensate for the lag of transmitting the message. The 70 character (700 bits) $GPRMC message requires 73 ms at 9600 baud. The time at which the data are valid may not be the present time; note that the GGA and RMC messages have the same time tag.

Note that the example gives several different estimates of position, even though nothing has moved.

Serial Connection

The Duemilenove, Uno and Leonardo have only a single hardware serial port, and we like to use it for the monitor. We can get a second serial port by using “soft serial” port. The shield uses software to create a serial port on digital pins 7 and 8. The Mega does not support soft serial on these pins. However, the Mega has four hardware serial ports on digital pins (0,1), (14,15), (16,17) and (18,19). For the Mega, connect the GPS serial lines to one of the Arduino serial pairs. The GPS serial pins are in a row of six pins that do not connect to the Arduino. Wire GPS Rx to a Mega Tx and GPS Tx to a Mega Rx. For instance black wire from GPS Rx to Arduino D14 Tx3, gray wire from GPS Tx to Arduino D15 Tx3.

Go to https://github.com/adafruit/Adafruit-GPS-Library and click on “Download ZIP”. Rename the folder to Adafruit_GPS and move to your sketchbook/libraries folder. Select Sketch | Import Library … | Add Library … Then upload File | Examples | Adafruit_GPS | leo_echo.

For Mega only, modify leo_echo to comment out //SoftwareSerial mySerial(8, 7);. Uncomment hardwareSerial mySerial = Serial3;

For all processors, set the switch to “Soft Serial”, open the monitor, and set baud rate to 57600. You should see GPS data similar to that in the example above.

Exercise: Modify the code to display only the RMC and GSA messages. Be sure to compute the checksum correctly. See http://www.adafruit.com/datasheets/PMTK_A08.pdf

Micro-SD Card

Insert a micro-SD card connector side down into the slot on the shield. For an Uno or Duemillenove, you are good to go. For Mega or Leonardo, update the SD card library. Seehttps://learn.adafruit.com/adafruit-data-logger-shield/for-the-mega-and-leonardo

For all processors, find the SD folder in your library, create a new folder called SD_Backup, and move the SD folder here. Download ZIP from https://github.com/adafruit/SD, rename it to SD, and copy to the old SD directory location. That location may be:

Windows: Program Files (x86) \ Arduino \ arduino-1.0.5 \ libraries \ SD

On Mac the directory is /Applications/Arduino-1.app/Contents/Resources/Java/SD, which you can manipulate with the Unix shell.

Start the Arduino IDE, and open Adafruit_GPS | shield_sdlog.

For Uno or Duemilenove, comment and uncomment code so that you have:

// if (!SD.begin(chipSelect, 11, 12, 13)) {

if (!SD.begin(chipSelect)) { // if you’re using an UNO, you can use this line instead

For the Mega, you will want the Adafruit version of SD that supports SD.begin(chipSelect, 11, 12, 13).

// SoftSerial …

#define mySerial Serial3

// see if the card is present and can be initialized:

if (!SD.begin(10, 11, 12, 13)) {

Alternatively, plug the Mega into a MegaShieldTrio board. The board wires lines 11, 12, and 13 to 50, 51 and 52 so that the standard lines work with the Mega.

Upload the code, and open the serial monitor at 115200 baud. You should see something like:

Ultimate GPSlogger Shield

Writing to GPSLOG03.TXT

Ready!

$GPGGA,191553.000,4740.2985,N,12218.6684,W,1,7,1.54,55.6,M,-17.3,M,,*58

OK

Log

$GPRMC,191553.000,A,4740.2985,N,12218.6684,W,0.17,268.94,110614$GPGGA,191554.000,4740.2984,N,12218.6683,W,1,7,1.54,55.6,M,-17.3,M,,*59

OK

Log

Remove the USB Cable and take the SD card out of the shield. Put the SD card into an adapter so that you can read it from a PC. Change the file extension from .TXT to .CSV and open with a spreadsheet. You should see something like:

Lab7_GPS_html_490f6548

Portable GPS

Put the SD card back into the shield. Take the Arduino with GPS shield and a 9.6 V battery and cable outside. When you plug it in, you have a portable GPS system. When the red LED goes out, you have a satellite fix and are acquiring valid data. Walk around the block (or drive) and it will trace your path. When you are done, unplug the device. Transfer the SD card to your computer. Open your trip file in a spreadsheet and sort it to isolate the $GPRMC items in chronological order. You may wind up with several files as you lose and reacquire GPS. Use the template GPS_UWB to produce a graphic of your path. Replace columns A through L of the template with your data, and use columns M though P to convert positions to meters. You may want to change the origin to something appropriate.

Software

Software from Adafruit can be used with minor modifications.

Hardware

Adafruit Ultimate GPS+Logging shield plus an Arduino.

Status (6/12/14): GPS Shield has been tested on Duemilenove, and on Mega with and without MegaShieldTrio. GPS and logging to SD card works.

Open Source Autonomy