Writing Your Own GPS Applications: Part 2

In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.

Introduction

In Part 1 of this article, I described how to write an interpreter for raw GPS NMEA data. The article included source code in VB.NET which harnessed the power of GPS satellites to determine the current location, synchronize the computer clock to atomic time, and point to a satellite on a cloudy day. The interpreter also works with hand-held devices and supports international developers. Yet, the interpreter was really not suitable for commercial use because it did not monitor precision. Without precision, an application could end up making unintelligent business decisions such as accidentally telling a driver to turn left into an alley, or worse. In this second part, I'll cover precision in detail and talk about what it takes to make GPS applications smart enough for in-car navigation and reliable enough for commercial use.

Causes of Precision Error

There are several phenomenon which can cause poor precision. For example, when satellite radio signals are transmitted, they are distorted by the troposphere and especially the ionosphere. In fact, satellites very low on the horizon are not good for getting a fix because the signals travel through so much of the atmosphere. Some GPS devices may even exclude these satellites from a fix to avoid the precision problems they would cause.

Figure 2-1: Satellite 1's radio signal travels through less of the atmosphere, resulting in less distortion. Satellite 2 is low on the horizon, however, resulting in significant atmospheric distortion.

Fortunately, atmospheric distortion can be measured and corrected for the most part. This is achieved by the use of GPS ground stations, fixed locations which constantly measure distortions in satellite radio signals. Calculated corrections are then broadcasted by radio which, when combined with the actual satellite signal, give a GPS receiver the ability to correct distortions in real-time.

Precision errors can be compounded by slight inaccuracies in each satellite’s “ephemeris”. Ephemeris is a table giving the coordinates of a celestial body over time. If the satellite's actual course deviates from its ephemeris, precision can be further diluted. This sort of error can only be corrected by firing small rockets on the satellites themselves. Adjustments are transmitted from the GPS Master Control Station at Schriever Air Force Base in Colorado Springs, Colorado.

Figure 2-3: Deviations in a satellite's actual orbit path can also cause loss in precision.

As I covered in Part 1 of this article, each GPS satellite has four on-board atomic clocks: two cesium atomic clocks and two rubidium atomic clocks which are accurate to 1 second per 300,000 years! Still, even microfractions of a second error in these clocks can cause positional error because distance is measured at the speed of light. The Master Control Station keeps these errors at a minimum by uploading corrective information to satellites twice a day, every day.

The last detriment to GPS precision is an effect called "multipath", which is an effect caused when a receiver receives not only the satellite's signal, but additional signals which bounced off buildings and other obstacles. Deflected signals take a longer path to the receiver and are thus delayed. If they are used by the receiver, the measured distance to a satellite is overestimated, resulting in inaccurate multilateration. More advanced receivers solve multipath problems by utilizing only the first signal detected (which is the most direct path from the satellite), then discarding any delayed signals.

Figure 2-4: A receiver is confused by "multipath", where several reflected signals are received (red) along with the direct radio signal (green).

Solving all of these precision problems is done by using more sophisticated GPS receivers which use real-time correction data such as WAAS (for North America) and EGNOS (for Europe). Yet, these problems cause relatively small inaccuracies when compared with Geometric Dilution of Precision, which can cause a receiver to be inaccurate by more than an American football field. Fortunately, Geometric DOP is the easiest to manage with the right programming techniques.

Geometric Dilution of Precision

GPS devices calculate your position using a technique called “3-D multilateration”, which is the process of figuring out where several spheres intersect. In the case of GPS, each sphere has a satellite at its center; the radius of the sphere is the calculated distance from the satellite to the GPS device. Ideally, these spheres would intersect at exactly one point, causing there to be only one possible solution to the current location, but in reality, the intersection forms more of an oddly-shaped area. The device could be located within any point in the area, forcing devices to choose from many possibilities. Figure 2-4 shows such an area created from three satellites (using part one’s $GPGSV sentence). The current location could be any point within the gray-colored area. Precision is said to be “diluted” when the area grows larger, which leads to this article’s focus: dilution of precision. The monitoring and control of dilution of precision (or DOP for short) is the key to writing high-precision applications.

Figure 2-5: GPS devices must choose one of several possible solutions to the current location.

DOP values are reported in three types of measurements: horizontal, vertical, and mean. Horizontal DOP (or HDOP) measures DOP as it relates to latitude and longitude. Vertical DOP (or VDOP) measures precision as it relates to altitude. Mean DOP, also known as Position DOP (PDOP), gives an overall rating of precision for latitude, longitude and altitude. Each DOP value is reported as a number between one and fifty where fifty represents very poor precision and one represents ideal accuracy. Table 2-1 lists what I believe to be an accurate breakdown of DOP values.

DOP

Rating

Description

1

Ideal

This is the highest possible confidence level to be used for applications demanding the highest possible precision at all times.

2-3

Excellent

At this confidence level, positional measurements are considered accurate enough to meet all but the most sensitive applications.

4-6

Good

Represents a level that marks the minimum appropriate for making business decisions. Positional measurements could be used to make reliable in-route navigation suggestions to the user.

7-8

Moderate

Positional measurements could be used for calculations, but the fix quality could still be improved. A more open view of the sky is recommended.

9-20

Fair

Represents a low confidence level. Positional measurements should be discarded or used only to indicate a very rough estimate of the current location.

21-50

Poor

At this level, measurements are inaccurate by as much as half a football field and should be discarded.

Table 2-1: Jon’s interpretation of dilution of precision values.

Looking again at figure 2-4, three satellites created a large area of possible solutions. This situation could be improved by two factors: adding more satellites to the fix, and using satellites evenly distributed throughout the sky. What would figure 2-4 look like if the situation was improved like this? Figure 2-5 shows Figure 2-4 after three more evenly-distributed satellites have been added.

Figure 2-6: Three more evenly-distributed satellites are added to figure 2-4, creating a high-precision environment where dilution of precision is low.

Determining Precision Needs

Now that the mechanics of precision have been explained, the next step is to figure out how to determine the actual precision needs of an application. As a general rule of thumb, an HDOP value of six or less is recommended for any application which makes suggestions to the user based on the current location. For example, in-car navigation programs which tell the user to “turn left now” should ignore positional measurements when HDOP is greater than six. But is six really good enough? How can developers figure out which HDOP values to use for their own applications? To answer these kinds of questions, I like to use a simple formula:

Accuracy of GPS Device * DOP = Maximum Allowable Error

This formula uses DOP as a factor of error which, when combined with the accuracy of the GPS device being used, yields the maximum error allowed by a level of DOP in the form of a specific, measurable distance. Another general rule of thumb is that typical consumer GPS devices are capable of between 5-7 meters of accuracy without enhancements like DGPS or WAAS, or an average of six meters. Using the in-car navigation HDOP of six and a typical GPS device, the maximum error allowed is 6m * 6 = 36 meters, or 118 feet. Given that a downtown city block is roughly 475 feet square, the maximum allowable error is about a quarter of a city block. This is precise enough to make sure that the driver turns at the correct road. On the other hand, an HDOP of twelve results in an allowable error of half a city block (237 feet), which could cause drivers to turn down an alley accidentally. So, using the formula, it is possible to use an HDOP greater than six for in-car navigation, but not by much.

The trick to using this formula is researching real-world distances, especially the smallest important distances. To demonstrate, take a look at golf. Does golf require more precision than in-car navigation? A golf program needs to tell the user which golf club to use in order to make the best shot. Some research into important golf distances finds that for most players, there is a regular distance interval between clubs of about 10-15 yards. Therefore, a golf program needs no more than 10 yards (9.1 meters) of allowable error to consistently suggest the right club. When 9.1 meters is put into the formula as Maximum Allowable Error, the maximum HDOP comes out to 3. So, golfing applications require about twice the precision as in-car navigation systems.

Why not skip the formulas and always enforce an HDOP of one? This looks like a reasonable practice, but greater precision requires greater satellite visibility. An in-car navigation system will probably not get an HDOP of one (or even three) downtown because signals are being obscured by buildings. If the enforced HDOP is too small, the application will throw out too many positional readings and just sit there while the driver loses patience. Golfing applications, on the other hand, can realistically enforce a small HDOP because they operate outdoors. The golfer’s PDA is likely to have plenty of open sky enough to pick up several evenly-distributed satellites, unless their ball is in the middle of the woods, in which case they're on their own.

To summarize, successful GPS software developers will use the formula to determine the greatest possible DOP number. This will ensure that the application minimizes most problems due to inaccuracy while at the same time allowing the application to function in the poorest possible satellite visibility conditions. This practice will maximize the value and versatility of any GPS application.

Enforcing Precision

Now that the precision needs of a GPS application can be determined, it’s time to find out what source code is necessary to extract and enforce maximum DOP values. All DOP measurements are packaged into the $GPGSA sentence every few seconds. Here is a sample of a $GPGSA sentence:

$GPGSA,A,3,11,29,07,08,5,17,24,,,,,,2.3,1.2,2.0*30

A skillful GPS application developer could know if positional readings are precise enough to use just by looking at one $GPGSA sentence. Again, the best DOP ratings occur when there are several satellites involved in a fix and the satellites are evenly distributed throughout the sky and at separate elevations -– hitting the GPS device from all angles, so to speak.

The last three words of this sentence are 2.3, 1.2, and 2.0, representing mean, horizontal and vertical DOP, respectively. This sentence represents a high-precision environment (suitable enough for both golfing and driving). Using the final listing from part 1 of this article (Listing 1-8), a method called ParseGPGSA is added which extracts DOP values and reports them via three events: HDOPReceived, VDOPReceived and PDOPReceived.

High Precision in Action

Enforcing maximum DOP values is the easiest part of the whole programming process because enforcing precision is a matter of ignoring positional measurements above your maximum allowable DOP amount. This can be done in one if statement. To best demonstrate this, I've written a small application (the "Demo" linked at the start of this article) which uses the NMEA interpreter to enforce a maximum DOP of 6.

And that's it! Armed with a deep understanding of GPS precision and how to keep it tightly controlled, you can now develop location-based services suitable for the real world.

Conclusion

There are several ways to distort a GPS satellite signal. Some are corrected by the Department of Defence and others can be corrected in your GPS receiver using real-time ground station correction signals. The only precision problem which is left to you to control is Geometric Dilution of Precision. Controlling GDOP is the key to writing commercial-grade GPS applications. A small mathematical formula can be applied to determine the maximum allowable DOP for a particular application. The maximum allowable error should be the greatest possible value which minimizes accuracy problems while maximizing operational conditions.

Another factor which helps developers is time itself. Advances in GPS receiver technology are pushing precision to new levels. While precision can be questionable with any consumer GPS device, there will soon be a time when precision to a centimeter is possible. I believe that this level of precision will cause a revolution in industry and pave the way for some truly amazing things: automated construction machines, tracking for every shipping container in the world, traffic control systems that actively prevent traffic jams... and self-guiding golf balls.

The next part of this series deals with mapping, getting GPS data and other geographic information to display in your .NET applications.

Share

About the Author

Hi there! From 2004 to 2009 I ran a company called "GeoFrameworks," publishing two components called GPS.NET and GIS.NET which helped developers quickly write location-based services. Now, I've released the source code for GPS.NET to CodePlex for you to use as you see fit.

Comments and Discussions

Now, more than ever, languages tend to "blur", as most of them will compile into almost the same "executable" code (at least regarding the original vb.net or c# code syntax)
So, I think you did well in choosing VB to reach everyone.

(And no, I'm not a "newbie" programmer defending VB... I've been programming in every other major coding laguages since the ASM of the 8086

Forget about being harassed about using VB.Net as part of your articles. I devwlop in many languages depending on the client. As far as Dot Net is concerned, same thing different syntax! Given a chioce, I prefer Vb.Net.

The logic of coding is more important to me than the language itself. I'm a c_programming_guru and I feel that the point of the article is to clarify, the basic handling of NMEA-0183 sentences, in which the logic will then become applicable to the language of preference.

The logic of coding is more important to me than the language itself. I'm a c_programming_guru and I feel that the point of the article is to clarify, the basic handling of NMEA-0183 sentences, in which the logic will then become applicable to the language of preference.

I love this product. Excellent Job on this product, Jon Person !. I'm really excited infact I am going to go buy and support
your product 360%!... I just have to correct 1 minor error. I feel you should be aware or maybe your are already....don't know
might have been a typo,... I'm not much of a C# coder but, I believe during the ParseGPGSV() function, which is suppose to
parse the "Satellites in View" $GPGSV sentence.... If you look closesly. During the... public bool ParseGPGSV(string sentence)

Otherwise I believe it would return the same value from the Azimuth extraction. So you wouldn't get any SNR information to
be able to base precision correctly. For the future of dependability and reliability of code production, I post this correction. As
far as the Signal Strength of the satellites, within the Notification, of the Event call to,...

I believe it would generate incorrect results...to what ever is going to be done with the SNR variable.
Please feel free to e-mail me at deciphered_scripturez@yahoo.com for additional details...I really Thank you, Jon Person, for
your hard work and time put into this and I really would LOVE to help as much as possible...I believe in your product. !

P.S. This update may save many lives! ... Can you imagine lets say for example, the next block of words over you had,
"05, 62, 285, 32" in the example above, lets say you passed the third Word of 285 as the value I know 99 would be the highest possible value, but imagine the reliability of the signal being factored in the calculation based on the strength for precision. I assume maybe this would throw off a calculation significantly.

I've just started learning C# (migrating from VB6) and this is a very useful article considering my department deals with 2-3cm accuracy GPS data all the time. Its a shame I cant yet replace our $25,000 RTK GPS eqiupment with something like this...