r0nd0m
Newbie level 2
- Joined
- Oct 5, 2008
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Brazil - SC - Joinville
- Activity points
- 1,299
Hello guys, I confess I should been here before cause now Im in a hurry...
I have a bunch of code for parsing NMEA sentences from a GPS module and calculate the distance between two points.
The problem is that I need accuracy of at least 5 meters and Im having 1,4km error...
I've been through this problem for about 4 months, and I noticed its all about float rounding. Im so stuck on this and cant avoid PIC of rounding my formula which causes that error.
Look, its not that hard, Im using the big circles method (spherical trigonometry but the formula is simple):
I found the problem is when I try to take sin() and cos() at the very beginning. The numbers get rounded and the results are catastrophic.
I had to broke this formula in many pieces in a way PIC can process all of the variables without running dry of RAM. it's now like this:
Can you guys help me?
Thanks in advance.
I have a bunch of code for parsing NMEA sentences from a GPS module and calculate the distance between two points.
The problem is that I need accuracy of at least 5 meters and Im having 1,4km error...
I've been through this problem for about 4 months, and I noticed its all about float rounding. Im so stuck on this and cant avoid PIC of rounding my formula which causes that error.
Look, its not that hard, Im using the big circles method (spherical trigonometry but the formula is simple):
Code:
( acos( (cos(90-lat1)*cos(90-lat2)*cos(lon1-lon2)) + (sin(90-lat1)*sin(90-lat2) ) )*40.030/360;
I found the problem is when I try to take sin() and cos() at the very beginning. The numbers get rounded and the results are catastrophic.
I had to broke this formula in many pieces in a way PIC can process all of the variables without running dry of RAM. it's now like this:
Code:
(Ive already added some values extracted and converted into DEGREES from my NMEA sentence, the final result is supposed to be: 7.766,9078Km and it IS when I jump over the sin() cos() steps and make flutuante2 = 0.3444832 in fact, as I said, the problem seems to be on sin() cos() step.)
lat1 = 40.816667;
lat2 = -22.9;
lon1 = -73.966667;
lon2 = -43.166667;
dist_part1 = cos(lat1)*cos(lat2)*cos(lon2-lon1);
dist_part2 = sin(lat1)*sin(lat2);
flutuante2 = acos(dist_part1+dist_part2);
flutuante2 = (flutuante2*180)/pi;
distancia = (flutuante2*40.030)/360;
printf("\r\n\r\nDistancia ate o objetivo: %.4f",distancia*1000);
Can you guys help me?
Thanks in advance.