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