Go Down

### Topic: TinyGPS library and GPS accuracy - decimal place truncation (Read 2819 times)previous topic - next topic

#### alfurey

##### Mar 14, 2012, 04:18 pmLast Edit: Mar 14, 2012, 04:34 pm by al_f Reason: 1
Hi all,

have been using the tiny gps library and  a venus GPS (http://www.sparkfun.com/products/11058) . Got it reading the GPS today and parsing the data using the library. Thing is the data comes from the GPS latitude and longitude minutes to 6 decimal places but the library only returns 5.

The 6th dp wanders a little but is still useful. There is plenty of room in the long int that stores the lat and long - full data for each of latitude and longituse will be 8 numbers, i.e. 2 numbers for minutes and 6 decimal places.

No idea why you would truncate data like this!

Have looked in the library and being cpp is a little opaque for me who only generally uses C and matlab. It looks like the offending function is:
Code: [Select]
`unsigned long TinyGPS::parse_degrees(){  char *p;  unsigned long left = gpsatol(_term);  unsigned long tenk_minutes = (left % 100UL) * 10000UL;  for (p=_term; gpsisdigit(*p); ++p);  if (*p == '.')  {    unsigned long mult = 1000;    while (gpsisdigit(*++p))    {      tenk_minutes += mult * (*p - '0');      mult /= 10;    }  }  return (left / 100) * 100000 + tenk_minutes / 6;}`

Any ideas how to tweak this so that i can retain the last dp that i can see is there on the raw stream?

The basic code to get the data is below.

btw there is a method to get the data out as a float but it is still truncated.

Code: [Select]
`#include <TinyGPS.h>#include <NewSoftSerial.h>TinyGPS gps;#define RXPIN 10#define TXPIN 11NewSoftSerial nss(RXPIN, TXPIN);long lat, lon;unsigned long age, time, date, speed, course;unsigned long chars;unsigned short sentences, failed_checksum;bool newdata;void setup() {  Serial.begin(57600); // Radio serial    // set the data rate for the SoftwareSerial port  nss.begin(38400);    // prints title with ending line break } void loop(){  while (nss.available())  {    int c = nss.read();    gps.encode(c);  }  gps.get_position(&lat, &lon, NULL);      Serial.print("Latitude:  "); Serial.println(lat);    Serial.print("Longitude:  "); Serial.println(lon);    delay(10);}//__________________________________________________static bool feedgps(){  while (nss.available())  {    if (gps.encode(nss.read()))      return true;  }  return false;}`

#### hhermsen

#1
##### Jan 16, 2013, 12:24 pm
Found the answer in the reply of 'Michael Shimniok (Bot Thoughts)' on the Arduiniana TinyGPS page which referrers to a fix at http://pastebin.com/NcnR96T4.

Go Up