Dependencies:   MPU6050 MS5607 mbed

Committer:
YujiTakbuo
Date:
Mon Jul 31 14:13:59 2017 +0000
Revision:
1:570e3c6fd4bb
Parent:
0:e527984bccd1
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YujiTakbuo 0:e527984bccd1 1 /*
YujiTakbuo 0:e527984bccd1 2 alt →altitude
YujiTakbuo 0:e527984bccd1 3 pres →pressure
YujiTakbuo 0:e527984bccd1 4 acc →acceleration
YujiTakbuo 0:e527984bccd1 5 */
YujiTakbuo 0:e527984bccd1 6
YujiTakbuo 1:570e3c6fd4bb 7
YujiTakbuo 0:e527984bccd1 8 //todo 単位系どうなってるの?
YujiTakbuo 0:e527984bccd1 9
YujiTakbuo 0:e527984bccd1 10 #include "mbed.h"
YujiTakbuo 0:e527984bccd1 11 #include "math.h"
YujiTakbuo 0:e527984bccd1 12 #include "MPU6050.h"
YujiTakbuo 0:e527984bccd1 13 #include "MS5607I2C.h"
YujiTakbuo 0:e527984bccd1 14
YujiTakbuo 0:e527984bccd1 15 //todo defineの整理
YujiTakbuo 0:e527984bccd1 16 #define ALT_TOP 100
YujiTakbuo 0:e527984bccd1 17 #define ALT_LEAFING 300
YujiTakbuo 0:e527984bccd1 18 #define ACC 4*9.8
YujiTakbuo 0:e527984bccd1 19 #define COUNT 5
YujiTakbuo 0:e527984bccd1 20
YujiTakbuo 0:e527984bccd1 21
YujiTakbuo 0:e527984bccd1 22 MPU6050 mpu(p9,p10); //tx,rx
YujiTakbuo 0:e527984bccd1 23 MS5607I2C ms(p9,p10,false); //tx, rx, csピンがGND
YujiTakbuo 0:e527984bccd1 24 DigitalOut myled1(LED1);
YujiTakbuo 0:e527984bccd1 25 DigitalOut myled2(LED2);
YujiTakbuo 0:e527984bccd1 26 DigitalOut myled3(LED3);
YujiTakbuo 0:e527984bccd1 27 DigitalOut myled4(LED4);
YujiTakbuo 0:e527984bccd1 28 float alt=ms.getAltitude();
YujiTakbuo 0:e527984bccd1 29 float acc[3];
YujiTakbuo 0:e527984bccd1 30 float acc_total;
YujiTakbuo 0:e527984bccd1 31 float time_alt;
YujiTakbuo 0:e527984bccd1 32 float time_acc;
YujiTakbuo 0:e527984bccd1 33 int cnt_alt=0;
YujiTakbuo 0:e527984bccd1 34 int cnt_acc;
YujiTakbuo 0:e527984bccd1 35
YujiTakbuo 0:e527984bccd1 36 //todo 変数の追加
YujiTakbuo 0:e527984bccd1 37
YujiTakbuo 0:e527984bccd1 38 Timer timer;
YujiTakbuo 0:e527984bccd1 39
YujiTakbuo 0:e527984bccd1 40
YujiTakbuo 0:e527984bccd1 41
YujiTakbuo 0:e527984bccd1 42 void judge_top(){
YujiTakbuo 0:e527984bccd1 43
YujiTakbuo 0:e527984bccd1 44 while(1){
YujiTakbuo 0:e527984bccd1 45 if(ALT_TOP>=alt){
YujiTakbuo 0:e527984bccd1 46 cnt_alt++;
YujiTakbuo 0:e527984bccd1 47 }
YujiTakbuo 0:e527984bccd1 48 if(timer.read()>0.5){
YujiTakbuo 0:e527984bccd1 49 cnt_alt=0;
YujiTakbuo 0:e527984bccd1 50 }
YujiTakbuo 0:e527984bccd1 51 if(cnt_alt>=COUNT){
YujiTakbuo 0:e527984bccd1 52 myled1=1;
YujiTakbuo 0:e527984bccd1 53 //open the servos
YujiTakbuo 0:e527984bccd1 54 }else{
YujiTakbuo 0:e527984bccd1 55 myled1=0;
YujiTakbuo 0:e527984bccd1 56 }
YujiTakbuo 0:e527984bccd1 57 }
YujiTakbuo 0:e527984bccd1 58 }
YujiTakbuo 0:e527984bccd1 59
YujiTakbuo 0:e527984bccd1 60
YujiTakbuo 0:e527984bccd1 61 int main(){
YujiTakbuo 0:e527984bccd1 62 while(1){
YujiTakbuo 0:e527984bccd1 63 judge_top();
YujiTakbuo 0:e527984bccd1 64 }
YujiTakbuo 0:e527984bccd1 65 }