統合プログラム

Dependencies:   mbed Servo BMP180

Revision:
8:7209c810309d
Parent:
6:6fe6e3554a46
--- a/main.cpp	Thu Oct 28 14:44:25 2021 +0000
+++ b/main.cpp	Mon Nov 01 16:52:17 2021 +0000
@@ -1,30 +1,71 @@
 #include "mbed.h"
 #include "direction.h"
-#include "Landing_Judgement.h"
+#include "BMP180.h"
+#include "calculate.h"
+#define PIN_SDA D4
+#define PIN_SCL D5
+
 DigitalOut Nichrome(A6);
-            
+ 
 int main(){
-    int land_judgement1=0;
-    //着地判定
-    while(1){
-        land_judgement1 = Landing_Judgement.land();
-        if(land_judgement1==1){
-        break;
-        }  
+    BMP180 bmp180(PIN_SDA,PIN_SCL);
+    int x = 0,y = 0,n1 = 0, n2 = 0;
+    int i;
+    float h,dp,dt,dp0;
+    float a = 0,b = 0,dp_ave,dt_ave;
+    //hは高度、dpは気圧、dtは温度、dp0は海面気圧
+    bmp180.Initialize(27,BMP180_OSS_ULTRA_LOW_POWER);//27は府大の海抜高度
+    
+    //海面気圧を計算
+    for(i=0;i<15;i++){
+        if(bmp180.ReadData(&dt,&dp)){
+            a = a + dp;
+            b = b + dt;
+            n1 = n1 + 1;
+            n2 = n2 + 1;
+            wait(1);
+            }
+        }
+    
+    dp_ave = a / n1;
+    dt_ave = b / n2;    
+    dp0 = calculate_dp0(dp_ave,dt_ave);
+ 
+    //10秒以上高度10mにいた場合離陸判定       
+    while(x<10){
+            if(bmp180.ReadData(&dt,&dp)){
+                h = calculate_h(dp0,dp,dt);
+                if(h >= 10){
+                x = x + 1;
+                    }
+                wait(1);
+            }
     }
     
-    wait(5);
+    wait(10);    
+ 
+  //離陸判定後、10秒以上高度2m以下にいた場合着地判定    
+    while(y<10){
+            if(bmp180.ReadData(&dt,&dp)){
+                h = calculate_h(dp0,dp,dt);
+                if(h <= 2){
+                y = y + 1;
+                    }
+                wait(1);
+            }
+    }
+  //30秒待機                
     wait(30);
 
     //パラシュート分離
     Nichrome=1;
     wait(10);
     Nichrome=0;
-
-    //中間地点を経由してゴール地点まで自律移動
-    direction.walk();
+    
+    //中間地点を経由してゴール地点まで移動
+    direction hokou;
+    hokou.walk();
     
     return 0;
-
-}
-   
\ No newline at end of file
+    
+    }
\ No newline at end of file