Parsing GPS data
i got adafruit gps shield goal build rc car can follow waypoints. understand how set gps , print raw data via serial don't understand how extract longitude , latitude calculate distance.
according adafruit once parse data can use gps.latitude, gps.longitude data.
they provide example uses bunch of language don't understand. #ifdef. i'm new programming well.
the other issue i'm running if write gps.read() ; read gps error in compiler saying gps wasn't declared. in adafruits example never declared works.
can explain me how parse data? can't follow code don't know it's doing.
here's example
according adafruit once parse data can use gps.latitude, gps.longitude data.
they provide example uses bunch of language don't understand. #ifdef. i'm new programming well.
the other issue i'm running if write gps.read() ; read gps error in compiler saying gps wasn't declared. in adafruits example never declared works.
can explain me how parse data? can't follow code don't know it's doing.
here's example
code: [select]
#include <adafruit_gps.h>
#include <softwareserial.h>
softwareserial myserial(8, 7);
adafruit_gps gps(&myserial);
// if using hardware serial (e.g. arduino mega), comment
// out above 6 lines , enable line instead:
//adafruit_gps gps(&serial1);
// set gpsecho 'false' turn off echoing gps data serial console
// set 'true' if want debug , listen raw gps sentences.
#define gpsecho true
// keeps track of whether we're using interrupt
// off default!
boolean usinginterrupt = false;
void useinterrupt(boolean); // func prototype keeps arduino 0023 happy
void setup()
{
// connect @ 115200 can read gps fast enough , echo without dropping chars
// spit out
serial.begin(115200);
serial.println("adafruit gps library basic test!");
// 9600 nmea default baud rate adafruit mtk gps's- use 4800
gps.begin(9600);
// uncomment line turn on rmc (recommended minimum) , gga (fix data) including altitude
gps.sendcommand(pmtk_set_nmea_output_rmcgga);
// uncomment line turn on "minimum recommended" data
//gps.sendcommand(pmtk_set_nmea_output_rmconly);
// parsing data, don't suggest using either rmc or rmc+gga since
// parser doesn't care other sentences @ time
// set update rate
gps.sendcommand(pmtk_set_nmea_update_1hz); // 1 hz update rate
// parsing code work nicely , have time sort thru data, and
// print out don't suggest using higher 1 hz
// request updates on antenna status, comment out keep quiet
gps.sendcommand(pgcmd_antenna);
// nice thing code can have timer0 interrupt go off
// every 1 millisecond, , read data gps you. makes the
// loop code heck of lot easier!
useinterrupt(true);
delay(1000);
// ask firmware version
myserial.println(pmtk_q_release);
}
// interrupt called once millisecond, looks new gps data, , stores it
signal(timer0_compa_vect) {
char c = gps.read();
// if want debug, time it!
#ifdef udr0
if (gpsecho)
if (c) udr0 = c;
// writing direct udr0 much faster serial.print
// 1 character can written @ time.
#endif
}
void useinterrupt(boolean v) {
if (v) {
// timer0 used millis() - we'll interrupt somewhere
// in middle , call "compare a" function above
ocr0a = 0xaf;
timsk0 |= _bv(ocie0a);
usinginterrupt = true;
} else {
// not call interrupt function compa anymore
timsk0 &= ~_bv(ocie0a);
usinginterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run on , on again
{
// in case not using interrupt above, you'll
// need 'hand query' gps, not suggested :(
if (! usinginterrupt) {
// read data gps in 'main loop'
char c = gps.read();
// if want debug, time it!
if (gpsecho)
if (c) serial.print(c);
}
// if sentence received, can check checksum, parse it...
if (gps.newnmeareceived()) {
// tricky thing here if print nmea sentence, or data
// end not listening , catching other sentences!
// wary if using output_alldata , trytng print out data
//serial.println(gps.lastnmea()); // sets newnmeareceived() flag false
if (!gps.parse(gps.lastnmea())) // sets newnmeareceived() flag false
return; // can fail parse sentence in case should wait another
}
// if millis() or timer wraps around, we'll reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out current stats
if (millis() - timer > 2000) {
timer = millis(); // reset timer
serial.print("\ntime: ");
serial.print(gps.hour, dec); serial.print(':');
serial.print(gps.minute, dec); serial.print(':');
serial.print(gps.seconds, dec); serial.print('.');
serial.println(gps.milliseconds);
serial.print("date: ");
serial.print(gps.day, dec); serial.print('/');
serial.print(gps.month, dec); serial.print("/20");
serial.println(gps.year, dec);
serial.print("fix: "); serial.print((int)gps.fix);
serial.print(" quality: "); serial.println((int)gps.fixquality);
if (gps.fix) {
serial.print("location: ");
serial.print(gps.latitude, 4); serial.print(gps.lat);
serial.print(", ");
serial.print(gps.longitude, 4); serial.println(gps.lon);
serial.print("speed (knots): "); serial.println(gps.speed);
serial.print("angle: "); serial.println(gps.angle);
serial.print("altitude: "); serial.println(gps.altitude);
serial.print("satellites: "); serial.println((int)gps.satellites);
}
}
}
there gps application tinygps++ http://arduiniana.org/libraries/tinygpsplus/ might of great use you.
it has been "go to" solution reading gps nmea string, , easily.
doc
it has been "go to" solution reading gps nmea string, , easily.
doc
Arduino Forum > Using Arduino > Programming Questions > Parsing GPS data
arduino
Comments
Post a Comment