Dependencies: MPU6050 MS5607 mbed
main.cpp@0:e527984bccd1, 2017-07-31 (annotated)
- Committer:
- YujiTakbuo
- Date:
- Mon Jul 31 14:12:47 2017 +0000
- Revision:
- 0:e527984bccd1
- Child:
- 1:570e3c6fd4bb
201708???
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:e527984bccd1 | 7 | //todo 単位系どうなってるの? |
YujiTakbuo | 0:e527984bccd1 | 8 | |
YujiTakbuo | 0:e527984bccd1 | 9 | #include "mbed.h" |
YujiTakbuo | 0:e527984bccd1 | 10 | #include "math.h" |
YujiTakbuo | 0:e527984bccd1 | 11 | #include "MPU6050.h" |
YujiTakbuo | 0:e527984bccd1 | 12 | #include "MS5607I2C.h" |
YujiTakbuo | 0:e527984bccd1 | 13 | |
YujiTakbuo | 0:e527984bccd1 | 14 | //todo defineの整理 |
YujiTakbuo | 0:e527984bccd1 | 15 | #define ALT_TOP 100 |
YujiTakbuo | 0:e527984bccd1 | 16 | #define ALT_LEAFING 300 |
YujiTakbuo | 0:e527984bccd1 | 17 | #define ACC 4*9.8 |
YujiTakbuo | 0:e527984bccd1 | 18 | #define COUNT 5 |
YujiTakbuo | 0:e527984bccd1 | 19 | |
YujiTakbuo | 0:e527984bccd1 | 20 | |
YujiTakbuo | 0:e527984bccd1 | 21 | MPU6050 mpu(p9,p10); //tx,rx |
YujiTakbuo | 0:e527984bccd1 | 22 | MS5607I2C ms(p9,p10,false); //tx, rx, csピンがGND |
YujiTakbuo | 0:e527984bccd1 | 23 | DigitalOut myled1(LED1); |
YujiTakbuo | 0:e527984bccd1 | 24 | DigitalOut myled2(LED2); |
YujiTakbuo | 0:e527984bccd1 | 25 | DigitalOut myled3(LED3); |
YujiTakbuo | 0:e527984bccd1 | 26 | DigitalOut myled4(LED4); |
YujiTakbuo | 0:e527984bccd1 | 27 | float alt=ms.getAltitude(); |
YujiTakbuo | 0:e527984bccd1 | 28 | float acc[3]; |
YujiTakbuo | 0:e527984bccd1 | 29 | float acc_total; |
YujiTakbuo | 0:e527984bccd1 | 30 | float time_alt; |
YujiTakbuo | 0:e527984bccd1 | 31 | float time_acc; |
YujiTakbuo | 0:e527984bccd1 | 32 | int cnt_alt=0; |
YujiTakbuo | 0:e527984bccd1 | 33 | int cnt_acc; |
YujiTakbuo | 0:e527984bccd1 | 34 | |
YujiTakbuo | 0:e527984bccd1 | 35 | //todo 変数の追加 |
YujiTakbuo | 0:e527984bccd1 | 36 | |
YujiTakbuo | 0:e527984bccd1 | 37 | Timer timer; |
YujiTakbuo | 0:e527984bccd1 | 38 | |
YujiTakbuo | 0:e527984bccd1 | 39 | |
YujiTakbuo | 0:e527984bccd1 | 40 | |
YujiTakbuo | 0:e527984bccd1 | 41 | void judge_top(){ |
YujiTakbuo | 0:e527984bccd1 | 42 | |
YujiTakbuo | 0:e527984bccd1 | 43 | while(1){ |
YujiTakbuo | 0:e527984bccd1 | 44 | if(ALT_TOP>=alt){ |
YujiTakbuo | 0:e527984bccd1 | 45 | cnt_alt++; |
YujiTakbuo | 0:e527984bccd1 | 46 | } |
YujiTakbuo | 0:e527984bccd1 | 47 | if(timer.read()>0.5){ |
YujiTakbuo | 0:e527984bccd1 | 48 | cnt_alt=0; |
YujiTakbuo | 0:e527984bccd1 | 49 | } |
YujiTakbuo | 0:e527984bccd1 | 50 | if(cnt_alt>=COUNT){ |
YujiTakbuo | 0:e527984bccd1 | 51 | myled1=1; |
YujiTakbuo | 0:e527984bccd1 | 52 | //open the servos |
YujiTakbuo | 0:e527984bccd1 | 53 | }else{ |
YujiTakbuo | 0:e527984bccd1 | 54 | myled1=0; |
YujiTakbuo | 0:e527984bccd1 | 55 | } |
YujiTakbuo | 0:e527984bccd1 | 56 | } |
YujiTakbuo | 0:e527984bccd1 | 57 | } |
YujiTakbuo | 0:e527984bccd1 | 58 | |
YujiTakbuo | 0:e527984bccd1 | 59 | |
YujiTakbuo | 0:e527984bccd1 | 60 | int main(){ |
YujiTakbuo | 0:e527984bccd1 | 61 | while(1){ |
YujiTakbuo | 0:e527984bccd1 | 62 | judge_top(); |
YujiTakbuo | 0:e527984bccd1 | 63 | } |
YujiTakbuo | 0:e527984bccd1 | 64 | } |