user34182: I'm currently working on a project involving making a "parent-child distance warning system" with my Flora board + Ultimate GPS Module (https://www.adafruit.com/product/1059).
I'm on the preliminary phase and just trying to retrieve the current GPS module position, comparing it with a pre-fixed position (expressed in GPS decimal coordinates, e.g. 40.779006, -74.289395), calculate the distance between these two points and, if the distance is more than a certain value, say 20 meters, print on serial monitor a warning message.
I was able to correctly retrieve the GPS module position (expressed in decimal coordinates, as above), but when I try to calculate the distance I'm not able to achieve a few-meter accurancy.
So, my questions are:

Is there a specific/best formula to calculate short distances (max 100 meters) on the earth surface with an accurancy of 2-3 meters?
I tried with Haversine formula with not so bad results, but because of the scarce Double precision (in ATMega processors is the same of the Float one, i.e. 32 bits), I'm able to obtain a precision of only 6-7 digits in total (as stated in https://www.arduino.cc/en/Reference/Float). These approximations lead to large errors in the final distance value.
How can I obtain a fast and precise position update during my path?
If I walk along a direction I'm no able to retrieve a fast enough position update in terms of lat/lon coordinates.

Hope to be as much clear as possible and to have explained my problem, thanks in advance to anyone will give me any feedback or any information and please be patience for my bad english.
Filippo
[UPDATE]
@EdgarBonet that's exactly what I was looking for!!! Huge thanks!
Does the simple GPS library you linked is good to me also if my Flora board mounts an AtMega32u4 processor instead of the ATtiny85 you mentioned?
Last question: do you know how faster can I retrieve a GPS fix? I mean, if I am in a certain position (say X) and I am able to correctly obtain my GPS coordinates, then I move 5 meters ahead (say X+5), when I arrive at X+5 position can I retrieve within few seconds the X+5 GPS coordinates?
Thank you so much again @EdgarBonet!!
I'm currently working on a project involving making a "parent-child distance warning system" with my Flora board + Ultimate GPS Module (https://www.adafruit.com/product/1059).
I'm on the preliminary phase and just trying to retrieve the current GPS module position, comparing it with a pre-fixed position (expressed in GPS decimal coordinates, e.g. 40.779006, -74.289395), calculate the distance between these two points and, if the distance is more than a certain value, say 20 meters, print on serial monitor a warning message.
I was able to correctly retrieve the GPS module position (expressed in decimal coordinates, as above), but when I try to calculate the distance I'm not able to achieve a few-meter accurancy.
So, my questions are:

Is there a specific/best formula to calculate short distances (max 100 meters) on the earth surface with an accurancy of 2-3 meters?
I tried with Haversine formula with not so bad results, but because of the scarce Double precision (in ATMega processors is the same of the Float one, i.e. 32 bits), I'm able to obtain a precision of only 6-7 digits in total (as stated in https://www.arduino.cc/en/Reference/Float). These approximations lead to large errors in the final distance value.
How can I obtain a fast and precise position update during my path?
If I walk along a direction I'm no able to retrieve a fast enough position update in terms of lat/lon coordinates.

Hope to be as much clear as possible and to have explained my problem, thanks in advance to anyone will give me any feedback or any information and please be patience for my bad english.
Filippo
[UPDATE]
@EdgarBonet that's exactly what I was looking for!!! Huge thanks!
Does the simple GPS library you linked is good to me also if my Flora board mounts an AtMega32u4 processor instead of the ATtiny85 you mentioned?
Last question: do you know how faster can I retrieve a GPS fix? I mean, if I am in a certain position (say X) and I am able to correctly obtain my GPS coordinates, then I move 5 meters ahead (say X+5), when I arrive at X+5 position can I retrieve within few seconds the X+5 GPS coordinates?
Thank you so much again @EdgarBonet!!
[UPDATE 2]
The DistanceBetween method recommended to me by @EdgarBonet returns to me always 0, even if I move my self a couple of tens of meters.
But, maybe I am wrong in passing the parameters. Do I have to pass the lat/lon parameters as decimal coordinates (e.g: 45.892829, 12.082583)? If I am wrong, in which format do I have to pass the lat/lon parameters to the DistanceBetween method?

user1585: I have successfully used an Arduino + hobby GPS to get an accuracy within a few meters with an update every second using normal floating point on Arduino. This should be possible.
A 32-bit float has 24 bits of precision, and one 2^24th of half the Earth's circumference is about 1.2 meters, so the theoretical cap is roughly that.
If I recall correctly, you would get better accuracy for short distances on a 32-bit float using normal 2D trig than haversine, but both should work.
Check to make sure you are reading your GPS correctly and go over the equations again. Is everything converted to radians correctly for the trig? Make sure your version of PI has enough digits. Are you correctly parsing the GPS output value as degrees+decimal minutes? It is not a simple decimal degree number (like Google Maps coordinates would be) if it came from an NMEA message. Are there any configuration startup commands you need to send your GPS unit?
I think the fastest updates you can expect is a new coordinate every second, but I haven't used your specific GPS.

user7508: The Haversine formula is way overkill for your needs. At the scale you
are concerned about, the Earth is essentially flat, so the distance
between two points is given by the standard Cartesian formula:
d = √(Δx2 + Δy2)
where Δx and Δy are the distances along the west–east and south–north
axes respectively. These can be computed from the differences in
latitude and longitude as
Δx = R Δλ cos(φ)
Δy = R Δφ
where φ is the latitude, λ is the longitude (both in radians), and R is
the Earth radius. The term cos(φ) accounts for the fact that, far from
the equator, consecutive meridians are closer together than consecutive
parallels. When computing this cosine, it does not matter whether you
use the latitude of either point.
I suggest you take a look at this simple GPS library. It was
designed for doing exactly this kind of simple calculations on a small
AVR processor like the ATtiny85. It should work great on your Flora. The
function you want is DistanceBetween(). It uses the “locally flat
Earth” approximation above, which is only good for distances up to a few
hundred kilometers.
A couple of things worth noting about this library:

the library trades accuracy for efficiency: everything is fixed-point
and it uses low-order polynomial approximations for cos(x) and
√(x2 + y2)
angles are given in units of 10−4 arc minutes, as this is
what you usually get from an NMEA sentence
DistanceBetween() reports the distance as an integer number of
meters, but you can easily modify it to give it in units of
half-meters, quarter-meters, etc.: just replace the value 512 in the
last line (return ... / 512;) by a smaller power of two.


34182: <p>I'm currently working on a project involving making a "parent-child distance warning system" with my Flora board + Ultimate GPS Module (<a href="https://www.adafruit.com/product/1059" rel="nofollow noreferrer">https://www.adafruit.com/product/1059</a>).
I'm on the preliminary phase and just trying to retrieve the current GPS module position, comparing it with a pre-fixed position (expressed in GPS decimal coordinates, e.g. 40.779006, -74.289395), calculate the distance between these two points and, if the distance is more than a certain value, say 20 meters, print on serial monitor a warning message.
I was able to correctly retrieve the GPS module position (expressed in decimal coordinates, as above), but when I try to calculate the distance I'm not able to achieve a <em>few-meter accurancy.</em></p>

<p>So, my questions are:</p>

<ol>
<li>Is there a specific/best formula to calculate short distances (max 100 meters) on the earth surface with an accurancy of 2-3 meters?
I tried with <em>Haversine formula</em> with not so bad results, but because of the scarce Double precision (in ATMega processors is the same of the Float one, i.e. 32 bits), I'm able to obtain a precision of only 6-7 digits in total (as stated in <a href="https://www.arduino.cc/en/Reference/Float" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/Float</a>). These approximations lead to large errors in the final distance value.</li>
<li>How can I obtain a fast and precise position update during my path?
If I walk along a direction I'm no able to retrieve a fast enough position update in terms of lat/lon coordinates.</li>
</ol>

<p>Hope to be as much clear as possible and to have explained my problem, thanks in advance to anyone will give me any feedback or any information and please be patience for my bad english.</p>

<p>Filippo</p>

<p><strong>[UPDATE]</strong></p>

<p>@EdgarBonet that's exactly what I was looking for!!! Huge thanks!</p>

<p>Does the simple GPS library you linked is good to me also if my Flora board mounts an AtMega32u4 processor instead of the ATtiny85 you mentioned?</p>

<p>Last question: do you know how faster can I retrieve a GPS fix? I mean, if I am in a certain position (say X) and I am able to correctly obtain my GPS coordinates, then I move 5 meters ahead (say X+5), when I arrive at X+5 position can I retrieve within few seconds the X+5 GPS coordinates?</p>

<p>Thank you so much again @EdgarBonet!!</p>

<p>I'm currently working on a project involving making a "parent-child distance warning system" with my Flora board + Ultimate GPS Module (<a href="https://www.adafruit.com/product/1059" rel="nofollow noreferrer">https://www.adafruit.com/product/1059</a>).
I'm on the preliminary phase and just trying to retrieve the current GPS module position, comparing it with a pre-fixed position (expressed in GPS decimal coordinates, e.g. 40.779006, -74.289395), calculate the distance between these two points and, if the distance is more than a certain value, say 20 meters, print on serial monitor a warning message.
I was able to correctly retrieve the GPS module position (expressed in decimal coordinates, as above), but when I try to calculate the distance I'm not able to achieve a <em>few-meter accurancy.</em></p>

<p>So, my questions are:</p>

<ol>
<li>Is there a specific/best formula to calculate short distances (max 100 meters) on the earth surface with an accurancy of 2-3 meters?
I tried with <em>Haversine formula</em> with not so bad results, but because of the scarce Double precision (in ATMega processors is the same of the Float one, i.e. 32 bits), I'm able to obtain a precision of only 6-7 digits in total (as stated in <a href="https://www.arduino.cc/en/Reference/Float" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/Float</a>). These approximations lead to large errors in the final distance value.</li>
<li>How can I obtain a fast and precise position update during my path?
If I walk along a direction I'm no able to retrieve a fast enough position update in terms of lat/lon coordinates.</li>
</ol>

<p>Hope to be as much clear as possible and to have explained my problem, thanks in advance to anyone will give me any feedback or any information and please be patience for my bad english.</p>

<p>Filippo</p>

<p><strong>[UPDATE]</strong></p>

<p>@EdgarBonet that's exactly what I was looking for!!! Huge thanks!</p>

<p>Does the simple GPS library you linked is good to me also if my Flora board mounts an AtMega32u4 processor instead of the ATtiny85 you mentioned?</p>

<p>Last question: do you know how faster can I retrieve a GPS fix? I mean, if I am in a certain position (say X) and I am able to correctly obtain my GPS coordinates, then I move 5 meters ahead (say X+5), when I arrive at X+5 position can I retrieve within few seconds the X+5 GPS coordinates?</p>

<p>Thank you so much again @EdgarBonet!!</p>

<p><strong>[UPDATE 2]</strong></p>

<p>The <code>DistanceBetween</code> method recommended to me by @EdgarBonet returns to me always 0, even if I move my self a couple of tens of meters.</p>

<p>But, maybe I am wrong in passing the parameters. Do I have to pass the lat/lon parameters as decimal coordinates (e.g: 45.892829, 12.082583)? If I am wrong, in which format do I have to pass the lat/lon parameters to the <code>DistanceBetween</code> method?</p>
 1585: <p>I have successfully used an Arduino + hobby GPS to get an accuracy within a few meters with an update every second using normal floating point on Arduino. This should be possible.</p>

<p>A 32-bit float has 24 bits of precision, and one 2^24th of half the Earth's circumference is about 1.2 meters, so the theoretical cap is roughly that.</p>

<p>If I recall correctly, you would get better accuracy for short distances on a 32-bit float using normal 2D trig than haversine, but both should work.</p>

<p>Check to make sure you are reading your GPS correctly and go over the equations again. Is everything converted to radians correctly for the trig? Make sure your version of PI has enough digits. Are you correctly parsing the GPS output value as degrees+decimal minutes? It is not a simple decimal degree number (like Google Maps coordinates would be) if it came from an NMEA message. Are there any configuration startup commands you need to send your GPS unit?</p>

<p>I think the fastest updates you can expect is a new coordinate every second, but I haven't used your specific GPS.</p>
 7508: <p>The Haversine formula is way overkill for your needs. At the scale you
are concerned about, the Earth is essentially flat, so the distance
between two points is given by the standard Cartesian formula:</p>

<p>d = √(Δx<sup>2</sup> + Δy<sup>2</sup>)</p>

<p>where Δx and Δy are the distances along the west–east and south–north
axes respectively. These can be computed from the differences in
latitude and longitude as</p>

<p>Δx = R Δλ cos(φ)<br>
Δy = R Δφ</p>

<p>where φ is the latitude, λ is the longitude (both in radians), and R is
the Earth radius. The term cos(φ) accounts for the fact that, far from
the equator, consecutive meridians are closer together than consecutive
parallels. When computing this cosine, it does not matter whether you
use the latitude of either point.</p>

<p>I suggest you take a look at this <a href="http://www.technoblogy.com/show?10WT" rel="noreferrer">simple GPS library</a>. It was
designed for doing exactly this kind of simple calculations on a small
AVR processor like the ATtiny85. It should work great on your Flora. The
function you want is <code>DistanceBetween()</code>. It uses the “locally flat
Earth” approximation above, which is only good for distances up to a few
hundred kilometers.</p>

<p>A couple of things worth noting about this library:</p>

<ul>
<li>the library trades accuracy for efficiency: everything is fixed-point
and it uses low-order polynomial approximations for cos(x) and
√(x<sup>2</sup> + y<sup>2</sup>)</li>
<li>angles are given in units of 10<sup>−4</sup> arc minutes, as this is
what you usually get from an NMEA sentence</li>
<li><code>DistanceBetween()</code> reports the distance as an integer number of
meters, but you can easily modify it to give it in units of
half-meters, quarter-meters, etc.: just replace the value 512 in the
last line (<code>return ... / 512;</code>) by a smaller power of two.</li>
</ul>
