![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
統合プログラム
Dependencies: mbed Servo BMP180
Diff: Landing_Judgement.h
- Revision:
- 0:e7b7def631c2
- Child:
- 1:bb89b58cfa0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Landing_Judgement.h Thu Oct 21 01:58:35 2021 +0000 @@ -0,0 +1,78 @@ +#include "mbed.h" +#include "BMP180.h" +#include "calculate.h" +#define PIN_SDA D4 +#define PIN_SCL D5 + +BMP180 bmp180(PinName PIN_SDA,PinName PIN_SCL); +class Landing_Judgement:public BMP180{ + private: + BMP180 bmp180(PIN_SDA,PIN_SCL); + + + int x ,y ,n1 , n2 ; + int landing ; + float h,dp,dt,dp0; + float a ,b ,dp_ave,dt_ave; + //hは高度、dpは気圧、dtは温度、dp0は海面気圧 + + public: + /*ここの関数をlanding_judgementの中に入れ込んじゃいます + //landing()が1を返せば着地、0を返せば未着地 + int landing(){ + return landing_judgement; + } + */ + + //着地判定の計算を開始させる関数 + int landing_judgement(); +}; + +int Landing_Judgement::landing_judgement(){ + bmp180.Initialize(27,int 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); + + while(x<10){ + if(bmp180.ReadData(&dt,&dp)){ + h = calculate_h(dp0,dp,dt); + if(h >= 30){ + x = x + 1; + } + wait(1); + } + } + //10秒以上高度30mにいた場合離陸判定 + + wait(10); + + while(y<10){ + if(bmp180.ReadData(&dt,&dp)){ + h = calculate_h(dp0,dp,dt); + if(h <= 10){ + y = y + 1; + } + wait(1); + } + } + + wait(5); + + landing_judgement = landing_judgement + 1; + return landing_judgement; + + //離陸判定後、10秒以上高度10m以下にいた場合着地判定 + +} \ No newline at end of file