zahidkhan
Member level 2
what is the efficient method of computing distance and bearing between two latitudes and longitudes using PIC 16F877 or 18F452.Using trig function consumes all rom.
any suggestions ?
any suggestions ?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
newelltech said:How do a few trig functions consume all of ROM?
How much ROM do you have?
Post your calculations, because it shouldn't be that math intensive.[/quot]
with 16f877A ROM usage for gps parsing is about 35% but including the following code ,ROM usage jumps to more than 80%. and yet goal is not achieved as calculations are not accurate.
Code:#include<math.h> #include<stdio.h> #define PI 3.141592654 #define EARTH 6371 void dist(); void dist() { float lat1,lat2,dlat,long1,long2,dlong,tmp1,tmp2,tmp3,tmp4,d,bearing; lat1=31.000000*PI/180; lat2=31.600000*PI/180; long1=74.002000*PI/180; long2=74.000000*PI/180; dlat=lat1-lat2; dlong=long1-long2; //tmp1=(sin(dlat/2)*sin(dlat/2))+cos(lat1)*cos(lat2)*(sin(dlong/2)*sin(dlong/2)); //tmp2=2*atan2(sqrt(tmp1),sqrt(1-tmp1)); //d=EARTH*tmp2; //d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(long2-long1))*EARTH; //bearing=atan2(sin(dlong).cos(lat2),cos(lat1).sin(lat2)-sin(lat1).cos(lat2).cos(dlong) ) tmp1=sin(dlong)*cos(lat2); tmp2=cos(lat1)*sin(lat2); tmp3=sin(lat1)*cos(lat2); tmp4=cos(dlong); d=atan2(tmp1,tmp2-(tmp3*tmp4)); tmp1=sin(lat2)-(sin(lat1)*cos(d)); tmp2=cos(lat1)*sin(d); bearing=tmp1/tmp2; printf(lcd_putc,"\%4.4f",d); printf(lcd_putc,"\n\%4.4f",bearing); }