Calculate distance Mega Ublox NEO 7M

I building a Odometer using Arduino Mega 2560, GPS module Ublox NEO 7M, 6 digit 7 seg display, the GPS is configurated to NAV-PVT, I calculate 10 times per second, I'm having precision problems, below the formula I use to calculate distance.
Thanks for your help

if (gps.ready())
{

lat2=((gps.lat)/10000000.0);
// Calcula somente quando mudar a coordenada
if(lat2 != latitudeanterior) {
veloc = (gps.gSpeed * 0.0036);
if(veloc > 0.1){
Serial.print(" Vel = ");
Serial.print (veloc);
latitudeanterior = lat2;
Serial.print (" Lat = ");
Serial.print(lat2,8);
long2=((gps.lon)/ 10000000.0);
Serial.print (" Lon = ");
Serial.print(long2,8);
diflat = radians(lat2 - lat1);// Calculo da distancia dos waypoints
flat1 = radians(lat1);
x2lat = radians(lat2);
diflon = radians((long2) - (long1));
dist_calc = (sin(diflat / 2.0) * sin(diflat / 2.0));
dist_calc2 = cos(lat1);
dist_calc2 *= cos(lat2);
dist_calc2 *= sin(diflon / 2.0);
dist_calc2 *= sin(diflon / 2.0);
dist_calc += dist_calc2;
dist_calc = (2 * atan2(sqrt(dist_calc), sqrt(1.0 - dist_calc)));
dist_calc *= 6371000.0;

Serial.print(" D=");
Serial.print (dist_calc,5);
Serial.print (" ");
if(digitalRead(22) == LOW) {
updown= 100;//Odom Aumenta
}
if(digitalRead(22) == HIGH) {
updown= -100;//Odom diminui
digitalWrite(BUZ, HIGH);
delay (10);
digitalWrite(BUZ, LOW);
}

//Odometro Acumulado
Serial.print (" a =");
a =dist_calcupdown + a;
Serial.print (a);
Serial.print (" ab =");
ab = a/1000;
Serial.println (ab);
lat1 = (lat2);
long1 = (long2);
}}}
d1=ab/10000;
d2=ab/1000-d1
10;
d3=ab/100-d210-d1100;
d4=ab/10-d310-d2100-d11000;
d5=ab/1-d4
10-d3100-d21000-d1*10000;
tm1637_6D.set(5);//BRIGHT_DARKEST = 0,BRIGHTEST = 7;
int8_t ListDisp[5] = {d5,d4,d3,d2,d1}; //first number will be displayed on the right
// The first point in the array will be displayed on the right
int8_t ListDispPoint[6] = {POINT_OFF,POINT_OFF,POINT_ON,POINT_OFF,POINT_OFF,POINT_OFF};
{
tm1637_6D.display(ListDisp, ListDispPoint);

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Part of the problem is that the AVR Arduinos do not support double precision floats.

But, consider telling us what you actually mean by "precision problems", and support it with one or more examples.

Hi,

Precision problems means traveling with my car, the 2 odometers ( car and arduino GPS) I have a diference betwen -12% up to +7%, them I assembly 2 GPS Odometer with Arduino, with diferent modules and antenas, the two Arduinos 100% the same distance, I test in 2 diferent cars and I have the same problem. How can I solve "AVR Arduinos do not support double precision floats" problem ?

Use an Arduino that support double float, a DUE for instance.

I have noticed that the speed indicated by my car is higher than the reading from a GPS. I suspect that this is done deliberately by the car manufacturer so that I can't blame them if I get a minor speeding ticket.

If speed is off, I would expect the odometer to be similarly affected.

I'd be inclined to drive a few miles on a highway with mile markers and compare.

According to a GPS and those roadside warning radars, my car displays a speed that is about 2mph higher than it should be.

My guess is that the faster you go the larger the difference between actual speed and Displayed speed.

Probably not, they can obvershoot a bit on the speed display for the reason you mentioned but still compute the right distance. Otherwise the car would report very wrong information accumulated over time

Last weekend I traveled to the south about 1,150 miles (1900 Km) , every 100 kilometers ( in the GPS's odometers) I compare the car odometer and the other 2 GPS odometers, The 2 GPS stay in the same number, but the car odometer came from 88km to 107km, I read 13 times the 3 odometers. I don't expect the same distance but, I don't understand why the proportion changes. I will buy a Arduino Due and try, in this case what I need to change in the programm to get the best results ?
Thanks everybody for your informations,

If this is a GPS odometer in a car, then if the car is travelling at circa 50mph and the GPS position update is at 10hz, you are taking position updates every 2.5m or so.

So if the distance between two position fixes is circa 2.5m for that calculated distance to be to acurate to say 1% what position accuracy would you need from the GPS ?

Not so! Federal Highway Admin has rules for the error % that you meter can have.

In France (Europe?) the rule is that the meter cannot show a speed that is inferior to the real speed and a tolerance is acceptable and this varies by type of vehicle (car, truck, motorbike, quad,…) and actual speed.

1% will be perfect, now I have up to 19%, I calculate the distance 10 times per second , I save the last position and wait for de next readind ( if its different to the memory) then I don't loose points . Sometime in a tunnel for example I save the last reading from GPS and when GPS is running again I have the next point to calculate, even loosing 200 points for example, if the tunnel is straight route. The odometer will be correct

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.