Floats, doubles, navigation and accuracy

Hi,

This a problem that seems to come up now and again on this forum, but either no-one’s posted a solution, or I’m too dumb to understand it.

Here goes....

I’m working on an autonomous vehicle project. The vehicle needs to travel a course starting from a given point, via various pre-programmed positions and then come back to the start point. It must get to within 100 meters of each of the turn points to qualify. During the course the GPS position is logged and once the vehicle has returned the logged GPS positions are used to determine if the vehicle really did manage to complete the course.

The geographical distance between two points is determined using ‘great circle’ math formula as described here.... http://www.movable-type.co.uk/scripts/latlong.html (note- all angles have to be expressed in radians, not degrees!)

It’s relatively easy to implement these formula in Arduino, the issue is that

Floats have only 6-7 decimal digits of precision

. (quoted from the reference pages). Unfortunately, this limited precision equates to several meters of inaccuracy.

The problem is that during the journey the actual latitude and longitude from the GPS module is logged verbatim to a SD card, and then converted to a number (in degrees) which is then converted to radians, and then used to work out if the vehicle reached the turnpoint. When the course has been finished, a different program (using floats with greater precision) is then used to verify the journey. So, during the journey the vehicle may think it’s got to within range of the turnpoint, but after the journey, the verifying program may decide it hasn’t!

To get greater accuracy, I’d normally just switch to a data type with greater precision, however the

double implementation is exactly the same as the float, with no gain in precision.

(quoted from the reference pages).

So what’s the solution? I think that I need to either find a data-type with greater precision, or find a set of great circle formula that work on integer values of degrees, minutes and seconds. Or do I have to move away from Arduino to a raspberry Pi instead?

Any suggestions?

thanks

Hi

From you description, you met a precision issue.
Why can’t you just using a simple multiply to keep precision before sending this to the later module?

eg 1/3 = 0.3333333
maybe you just keep the 6-7 digits which double

But you can change your module a little with

1000/3

Hope this works for you.
Of course, there will be more complicated way in keeping the precision.
Considering your algorithem complexity, this will be the fatest one

Or do I have to move away from Arduino to a raspberry Pi instead?

Or a Due with 64 bit doubles? Or an 8 bit Arduino, and use 9.23 fixed point? (8.24 isn't quite good enough for +/- 180 degrees)

Or a Due with 64 bit doubles? Or an 8 bit Arduino

Ahhh! didn't realize precision varied between different versions of arduino hardware! Thank you!