Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #15 on: May 28, 2012, 03:37:21 pm » |
What do you think the solution might be? You don't really say what the problem is.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius
|
 |
« Reply #16 on: May 28, 2012, 03:53:43 pm » |
all i want is to get number from this command : gps.f_get_position(&lat1, &lon1); in this format : lat1 = 32.11 lat2=34.78755 so i can use them with this command : gps.distance_between (lat1,lon1,lat2,lon2); if i send lat1 and lon1 as they come out from :gps.f_get_position(&lat1, &lon1); i get wrong answer but if i send them as shown above it works
|
|
|
|
|
Logged
|
louis
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 18
|
 |
« Reply #17 on: May 28, 2012, 04:11:12 pm » |
A variation of 0.01 equates to approx half a mile. So, +/- this on two readings could be a mile out!  What target accuracy are you trying to achieve?
|
|
|
|
|
Logged
|
I'll be glad when I've had enough!
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius
|
 |
« Reply #18 on: May 28, 2012, 04:31:20 pm » |
yes i know i want the latitude to be 2 points after the decimal and longititude to be 4 points after the decimal for example :
lat = 32.12 lon=34.1234 im trying to dig in the headers and cpp files of tiny gps library to change the way: gps.f_get_position(&lat1, &lon1); return numbers but with no luck untill now .
|
|
|
|
|
Logged
|
louis
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 31
Posts: 2930
I only know some basic electricity....
|
 |
« Reply #19 on: May 28, 2012, 06:01:24 pm » |
IEEE floating point has that problem, like when you should have 1.0 but you get .999999.
If you can find the way, do your work using fixed-point with unsigned longs or long longs and the digits won't shift. Even signed longs will give you a solid 9 places.
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Sydney
Offline
God Member
Karma: 14
Posts: 717
Big things come in large packages
|
 |
« Reply #20 on: May 28, 2012, 06:35:05 pm » |
GoForSmoke is right. Floating point representation in computers is largely approximate because of the way that the numbers are represented. If you want accuracy you should long integers (for example 32.11 can be 3211). As long as all the number are scaled up the same way (eg, by 100 in this case) then you are all correct and at the end you just insert the decimal in the right place if you need to.
|
|
|
|
« Last Edit: May 28, 2012, 07:08:26 pm by marco_c »
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 13
Posts: 899
|
 |
« Reply #21 on: May 28, 2012, 06:51:16 pm » |
i get wrong answer but if i send them as shown above it works Give an example of the returned lat and long and the wrong answer. And then show why what you want to do with the numbers is an improvement. Pete
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius
|
 |
« Reply #22 on: May 28, 2012, 08:07:26 pm » |
for example : lat1=32.11 lon1=34.8780 lat2=32.11 lon2=34.8781 the distance is 9.4m now i have lat1 and lon1 stored in the memory so i don't care about them . but to get lat2 and lon2 i need this function : gps.f_get_position(&lat2, &lon2); but this function keeps changing the coordinates all the time and any change in any digit is abig problem so i need to force this function to give the number as i want (2 digits . 4 digits) only ... this is how i done that with no sucess : gps.f_get_position(&lat11, &lon11); char buf2[30],buf3[5]; dtostrf(lon11, 2, 3, buf3); float lon1= atof(buf3); g=gps.distance_between (lat1,lon1,lat22,lon22);
|
|
|
|
|
Logged
|
louis
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6388
-
|
 |
« Reply #23 on: May 28, 2012, 08:47:11 pm » |
to get lat2 and lon2 i need this function : gps.f_get_position(&lat2, &lon2); but this function keeps changing the coordinates all the time and any change in any digit is abig problem so i need to force this function to give the number as i want (2 digits . 4 digits) only
Is your GPS giving credible values for lat and long? To what resolution are they accurate? Since the float data type will be capable of holding numbers with more precision than the accuracy of your GPS, the least significant digits will be affectively noise. You could ignore these since they won't affect the accuracy of your calculation - the result you get will have more digits than are accurate and you will have to round or ignore the extra digits in any case, so there is no significant benefit to also doing that rounding/truncation to the input figures. On the other hand, if the input figures from your GPS are varying wildly, maybe that is the root of your problem. If you're getting garbage in, everything else you calculate will also be garbage.
|
|
|
|
|
Logged
|
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 31
Posts: 2930
I only know some basic electricity....
|
 |
« Reply #24 on: May 28, 2012, 08:53:34 pm » |
Peter, I think that the GPS data being stuffed into 32-bit floats is one source of error. gps.f_get_position(&lat11, &lon11); char buf2[30],buf3[5]; dtostrf(lon11, 2, 3, buf3); float lon1= atof(buf3); g=gps.distance_between (lat1,lon1,lat22,lon22);
Does dtostrf() as you use it do rounding, as in rounding up or down? You could try converting the float to a string with more places than you need then placing a terminating zero after the last place you need, but with floats it may help repeatability while losing actual accuracy. In the very act of cutting off digits to get consistent results, the results will be consistently wrong. Anyway here is how that would work. I have a C string buf[12] with a number in it. text -- ASCII hex: 1.2345678 -- 31 2E 32 33 34 35 36 37 38 00 00 00 I cut off everything past the 4th decimal place: 1.2345 -- 31 2E 32 33 34 35 00 37 38 00 00 00 However when I convert that back into a float I don't expect it to equal 1.2345 but something close. I'm sure it works better with 64-bit floating point.
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius
|
 |
« Reply #25 on: May 28, 2012, 09:30:28 pm » |
im using em406a and its giving me the right lat and long of my home i checked in google, the problem is the change in the last tow numbers , for example : first call of the function : lat =32.1122 secound call : lat=32.1133 and this is a big problem for calculating distance .it works only with one change in the last number for example : lat=32.1122 lat=32.1123 the distance with one number change and tow numbers change is completly defferent . help me please ...
|
|
|
|
|
Logged
|
louis
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2310
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #26 on: May 28, 2012, 09:33:23 pm » |
It sounds like there is an issue with the GPS unit. The numbers shouldn't jump around as you describe... 10th's of a second accuracy mean many meters difference in position. is it a 3V3 device? and if so do you have it interfaced properly? and is the device properly bypassed, like a 10 uF and a 100 nF capacitor right at the device?. Do you have a clean signal to the GPS Unit ?. In my direct experience even close to a window, operation of a GPS unit inside a building can be problematical. Mine will occasionally return bad data and be difficult to achieve lock. IMO
Doc
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius
|
 |
« Reply #27 on: May 28, 2012, 09:45:31 pm » |
its 5 v device and its connected with gps arduino shield and the signal is ok im getting the time and speed and altitude with no problems ... i think that the problem is with this function: gps.f_get_position(&lat2, &lon2); but im not sure ...
|
|
|
|
|
Logged
|
louis
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 31
Posts: 2930
I only know some basic electricity....
|
 |
« Reply #28 on: May 29, 2012, 03:19:31 am » |
What region/country do you live?
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
UK
Offline
Edison Member
Karma: 44
Posts: 2224
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #29 on: May 29, 2012, 03:24:44 am » |
If you are doing constant reading (always updating your location) then a rolling average would definitely be best. That would smooth out those inconsistancies. I have written a small "average" library: http://hacking.majenko.co.uk/libs/average which does rolling averages for you: #include "Average.h" #define SMOOTH 10 float h_lat[SMOOTH]; float h_lon[SMOOTH];
...
gps.f_get_position(&lat2, &lon2); lat2 = rollingAverage(h_lat,SMOOTH,lat2); lon2 = rollingAverage(h_lon,SMOOTH,lon2);
If you're not doing constant reading, then you could do say 10 reads, and add them to a total (starting at 0), then divide that result by 10, to give a more accurate reading: float lat2,lon2; float tot_lat,tot_lon; unsigned char i;
tot_lat = tot_lon = 0;
for(i=0; i<10; i++) { gps.f_get_position(&lat2, &lon2); tot_lat += lat2; tot_lon += lon2; } lat2 = tot_lat/10.0; lon2 = tot_lon/10.0;
|
|
|
|
|
Logged
|
|
|
|
|
|