2014년 12월 1일 월요일

GPS speed and direction are very unstable


In my app, I calculate the speed of the tablet (!) by using the following -

1. It reads the latitude, longitude and system time and stores them

2. When the location changes, then
   2a. It stores the previous data in new lat/long variables
   2b. It stores the new readings of the same data

3. It calculates the speed by
  3a. It calculates the distance between the readings by calculating the length of the hypotenuse of the triangle with right sides (difference in long readings) and (difference in lat readings) and converts from degrees to nautical miles
  3b It calculates the time elapsed between the readings by subtracting the times
  3c It divides the distance by the time elapsed

I calculate the heading by -

4a. It calculates the angle from atan2 of the differences in lat and long readings
4b. It uses the modulo function on the angle

These seem to give generally sensible results, but the values jump around a lot. If I am stationary, the speed never seems to fall to zero, it jumps around up to say 50 knots, and the track varies all around the compass, as if the data from the sensor were noisy. My commercial GPS apps give smooth results, but respond quite quickly to changing speed (say), so it's not as if they are waiting for a long time between calculations to improve the result.

Sensor parameters tried have been distanceinterval = 2 and 5, and timeinterval = 500 and 2000

Please can anyone suggest why this happens, and how to fix it?

--
Read the LocationSensor tutorial.
1) Your distance calculation is very crude; there are better algorithms .   Look up Haversine algorithm, it is a great short distance algorithm for calculating point to point distances over short distances ... less than 10s of miles but it is reasonable to several hundred.  Vincenty's algorithm is accurate over all distances.  Simple trig, what you are doing is accurate for about a block or two...because of the curvature of the Earth.
2)  You will get 'descrepencies' in the reporting of Latitude and Longitude easily up to 40 or 50 meters.  Read the description of Accurracy in the tutorial.  The numbers reported by a GPS has a confidence of about 68% reliability that the fix is precise.  A GPS reading can be as precise as two meters +/- or easily +/- 20-30 meters depending on the number of satellites that the GPS actually used to get a 'fix'.  AI2 tells you how good the fix is with the Accuracy parameter.  Some compilers using Java can also tell how many satellites are actually used with the NEMA data ... AI2, unfortunately, can not capture that info.

So, if the fix is off by 2 to 40 meters, so will your distance calculations.
Ah, if you are setting the distance interval to 2, I understand a previous question,  AI2 and phones/tablets do a TERRIBLE job of using that parameter when the value is low.  Try using 100 meters and then your GPS icon will not stay solid.

3) What you measure is an instantaneous velocity...not the average velocity..when you measure discrete points.

How to fix?   The LocationSensor tutorial provides some remedies...

--
Thanks, Steve. All useful info which I'll incorporate. GPS still seems to be not working after the app closes (or even the tablet goes to sleep) and re-opens but I'll take on board the new info and do more experiments and post again if I'm stuck.

--
Hmm, having looked it up, I think I'll pass on Vincenty's algorithm.......

--
... but the Haversine was easy and seems to have improved it.

--
as a part of my app I need the same functionality, and was wondering could you please give me an advice for the following:
My distance calculation is Ok, but I'm having troubles with calculating time difference (getting run time errors of a  kind "operation cannot accept arguments like 1417329124337")

So did you use system time for all the readings? Converted it? Or maybe some call Clock1.FormatTime (Clock1.Now)?

--

댓글 없음:

댓글 쓰기