201803_oshima_jodam_test
Dependencies: BMP180 MPU6050 SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
Diff: main.cpp
- Revision:
- 10:273500c77873
- Parent:
- 9:b10aaf72d100
- Child:
- 11:0f8d26600248
--- a/main.cpp Fri Mar 09 14:14:57 2018 +0000 +++ b/main.cpp Sun Mar 11 13:50:11 2018 +0000 @@ -8,6 +8,7 @@ #define LOCK 0 #define TIMER 30 //開放タイマー #define RATE 50//判定周期 +#define ALT 1 //落下判断高度 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board BMP180 bmp(p28,p27); @@ -59,12 +60,27 @@ float _DMS2DEG(float raw_data); //GPSデータ60進数→10進数 void _para(int motion); void _recovery(); +int _input(char c); int main() { twe.baud(115200); twe.printf("Hello World!\r\n"); - _para(LOCK); + while(1){ + char c = twe.getc(); + if(_input(c) == 1){ + _para(UNLOCK); + twe.printf("servo_open\r\n"); + } + else if(_input(c) == 2){ + _para(LOCK); + twe.printf("servo_lock\r\n"); + } + else if(_input(c) == 3){ + break; + } + + } mpu.setAcceleroRange(0); mpu.setGyroRange(0); @@ -110,7 +126,7 @@ fp = fopen("/sd/mydir/sdtest.txt", "a"); if(fp == NULL)twe.printf("ERROR\r\n"); timer1.start(); - kaihou.attach(_open,1/RATE); +// kaihou.attach(_open,1/RATE); kaihou.attach(_open,0.02); @@ -163,13 +179,16 @@ i = 0; if(tf_para == true){ //パラ開くまでは頂点判定 Alt_buff[Cnt_buff+1] = Alt_now; - if(Alt_buff[Cnt_buff]-Alt_buff[Cnt_buff+1] > 1) Cnt_para++; //直前の値より小さければカウント+1 + if(Alt_buff[Cnt_buff]-Alt_buff[Cnt_buff+1] > ALT) Cnt_para++; //直前の値(0.2秒前より1ALTm降下)より小さければカウント+1 // twe.printf("Cnt_para:%d\r\n", Cnt_para); Cnt_buff++; if(Cnt_para == 10 || t > TIMER){ //頂点!!! kaihou.detach(); //SD閉じる前にサーボ動かす前にTicker止める fprintf(fp,"OPEN!\r\n"); - fclose(fp); + fclose(fp); + lfp = fopen("/local/Alt.txt","a"); + fprintf(lfp, "MAX:%f\r\n",Max_Alt); + fclose(lfp); _para(UNLOCK); tf_para = false; timer1.stop(); @@ -244,4 +263,16 @@ }else if(motion==LOCK){ servo_para.pulsewidth(0.002); // pulse servo outu sita } +} + +int _input(char c){ + + if(c=='f'){ + return 3; + }else if(c=='l'){ + return 2; + }else if(c=='u'){ + return 1; + } + return 0; } \ No newline at end of file