ルンパッパ

Dependencies:   mbed BMP180

Files at this revision

API Documentation at this revision

Comitter:
naruu
Date:
Sat Dec 19 16:22:46 2020 +0000
Parent:
9:02580f39e37e
Commit message:
ou;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Dec 19 15:44:22 2020 +0000
+++ b/main.cpp	Sat Dec 19 16:22:46 2020 +0000
@@ -14,7 +14,7 @@
 DigitalOut FET1(D9);//FETのピン
 DigitalOut FET2(D8);
 DigitalIn flight(D6);  //フライトピンのピン    
-DigitalOut SW(D7);//フライトピンの電圧降下ピン 
+DigitalOut SW(D7); 
 TB6612 motor(D7,D9,D11);//モータードライバーのピン
 GPS gps (D13,A7);                 
 
@@ -56,18 +56,21 @@
         }
    }
     
-    int n=0;
+    float avalt,x8;
+    float pressure,temperature,altitude;//気圧,気温,高度
     int t=0;
+
     xbee.printf("\rstart!\n\r");//気圧センサースタート
     bmp180.Initialize(27,BMP180_OSS_ULTRA_HIGH_RESOLUTION);//27は府大の海抜高度
     xbee.printf("initialization complete!\n\r");//初期化完了
 
-    while(1){
-        if(bmp180.ReadData(&temperature,&pressure)){
+ while(1){
           float x4,x5,x6,x7,a,b;
           float sum=0,altitude[11];
-            for(int p=1;p<11;p++){
-                a = pressure;
+          int r=0;
+        for(int p=1;p<11;p++){
+        if(bmp180.ReadData(&temperature,&pressure)){
+            a = pressure;
             b = temperature;
             x4 = 1019.11 / a; //海面気圧を気圧でわる
             x5 = powf(x4, 0.1902225); //5.257ぶんの1
@@ -76,29 +79,33 @@
             x8 = x7 / 0.0065;
             altitude[p] = x8;
             sum=sum+altitude[p];
+            r++;
+            xbee.printf("altitude(m)\t:%.3f\n\r",altitude[p]);
+            xbee.printf("--------------------------------\n\r");
+        }else{
+        xbee.printf("NO DATA\n\r");
+        xbee.printf("---------------------------\n\r");
+        wait(1);
             }
-            avalt=sum/10;
-            
-            
+            }
+            avalt=sum/(float)r;
             xbee.printf("Altitude(m)\t:%.3f\n\r",avalt);
             xbee.printf("--------------------------------\n\r");
             wait(3);
             break;
-            n=0;
-    }else{
-        xbee.printf("NO DATA\n\r");
-        xbee.printf("---------------------------\n\r");
-        wait(1);
         }
-    }
         while(1){
-            if(bmp180.ReadData(&temperature,&pressure)){
-                float y4,y5,y6,y7,y8,c,d;
+                float y4,y5,y6,y7,c,d;
+                float y8=avalt;
                 float speed;
                 float s=0;
-                float alti[11];
+                float alti[128];
                 float average_alti;
-                for(int q=1;q<11;q++){
+                int e=0;
+                int i=1;
+            
+        for(int q=1;q<11;q++){
+                if(bmp180.ReadData(&temperature,&pressure)){
                 c = pressure;
                 d = temperature;
                 y4 = 1019.11 / c; //海面気圧を気圧でわる
@@ -107,28 +114,34 @@
                 y7 = (y5 - 1) * y6;
                 y8 = y7 / 0.0065;
                 alti[q]= y8;
-                s=s+alti[q];
-                }
-                average_alti=s/10;
-                speed = (avalt - average_alti)/(float)(3+n);//値が取得でた場合は,3秒間の速さをだし,値が取得できなかった場合は3+n秒(nは値が取得できなかった回数)の速さをだす
+                 s=s+alti[q];
+                xbee.printf("高度%d回目%f\n\r",q-i,alti[q]);
+                xbee.printf("-------------------------------\n\r");
+                e++;
+                }else{
+                xbee.printf("NO_Data\n\r");
+                    }
+                 }   
+                average_alti=s/(float)e;
+                speed = (avalt - average_alti)/3;
                 
                 xbee.printf("Altitude(m)\t:%.3f\n\r",average_alti);
                 xbee.printf("Speed(m/s)\t:%.3f\n\r",speed);
                 xbee.printf("-------------------------------\n\r");
-                x8 = y8;
-                n=0;
-                wait(3);
+                
+                avalt=average_alti;
+                xbee.printf("tの値は%d\n",t);
+                i++;
                 if(speed<=0.5){
-                    t++;
-                    }
-            }else{xbee.printf("NO DATA\n\r");
-                    ++n;
-                    wait(1);
-                    }
-                    if(t=3){
+                    t=t+1;
+                    }if(t==3){
                         break;
                         }
-           }
+            wait(3);
+            }
+            }
+
+
            /*speedが3回0.5m/s以下になったらFETに20秒電流を流してその後電流を止める*/         
         FET1=1;
         wait(10);