gps
Embed:
(wiki syntax)
Show/hide line numbers
gps.cpp
00001 #include "mbed.h" 00002 #include "getGPS.h" 00003 #include"math.h" 00004 00005 Serial pc(USBTX,USBRX); 00006 GPS gps(D0,D1); 00007 Serial xbee(D0,D1); 00008 00009 int main(){ 00010 double a; 00011 double b; 00012 double distance; 00013 00014 pc.printf("GPS begin\n"); 00015 00016 while(1){ 00017 if(gps.getgps()){ 00018 /*a,bを緯度経度の初期値で初期化*/ 00019 a=gps.latitude; 00020 b=gps.longitude; 00021 printf("------------\r\n"); 00022 pc.printf("(北緯:%lf,東経%lf)\r\n",gps.latitude,gps.longitude);//緯度と経度を表示 00023 break; 00024 }else{ 00025 pc.printf("Fault_No_Data\r\n"); 00026 wait(1); 00027 } 00028 } while(1){ 00029 if(gps.getgps()){ 00030 printf("------------\r\n"); 00031 pc.printf("(北緯%lf,東経%lf)\n\r",gps.latitude,gps.longitude);//緯度と経度を表示 00032 00033 /*ここから距離の計算*/ 00034 /*c、dを得た緯度経度の値で初期化*/ 00035 double c; 00036 double d; 00037 c=gps.latitude; 00038 d=gps.longitude; 00039 00040 const double pi=3.14159265359;//円周率 00041 00042 /*ラジアンに変換*/ 00043 double theta_a=a*pi/180; 00044 double theta_b=b*pi/180; 00045 double theta_c=c*pi/180; 00046 double theta_d=d*pi/180; 00047 00048 double e=sin(theta_a)*sin(theta_c)+cos(theta_a)*cos(theta_c)*cos(theta_b-theta_d);//2点間のなす角を求める 00049 double theta_r=acos(e); 00050 00051 const double earth_radius=6378140;//赤道半径 00052 00053 distance=earth_radius*theta_r;//距離の計算 00054 00055 /*距離が20m以上なら表示、通信*/ 00056 if(distance>=20){ 00057 pc.printf("run 20m"); 00058 xbee.printf("run 20m"); 00059 break; 00060 } 00061 00062 }else { 00063 // xbee.print("False_No_Data\r\n"); 00064 pc.printf("False_No_Data\r\n"); 00065 wait(1); 00066 }//データ取得失敗を表示、通信、1秒待機 00067 } 00068 return 0; 00069 }
Generated on Sat Jul 16 2022 03:28:08 by
1.7.2