あの装置用
Dependencies: ADXL345_I2C QEI SDFileSystem mbed
Revision 7:0e3fac3c6a6a, committed 2017-03-05
- Comitter:
- ojityan
- Date:
- Sun Mar 05 18:48:04 2017 +0000
- Parent:
- 5:473edb6558fa
- Child:
- 8:9059f95fc498
- Commit message:
- ??????;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 09 07:10:47 2017 +0000 +++ b/main.cpp Sun Mar 05 18:48:04 2017 +0000 @@ -57,7 +57,7 @@ double v; double F_output; - myled1 = 1; + myled1 = 1; //起動の確認 ADXL_config(); myled2 = 1; // makefile(); @@ -71,14 +71,14 @@ myled4 = 0; -//---ammeter setting end--- +//---PWNの周期を設定--- duty_output = 0.6; duty.period(0.00005); // NVIC_SetPriority(0, 1); ///////////////////// -//---main routen--- +//---制御開始--- ///////////////////// while(1) { t.reset(); @@ -86,34 +86,32 @@ loop_break = 0; debug.printf("writing OK!\n"); - weight_init(); + weight_init(); //慣性力発生用おもりを初期位置に移動させる -//---sensing start--- +//---加速度を感知したら移動開始--- flipB_ = 0; dir = 1; while (1) { accelerometer.getOutput(readings); - if( abs((int16_t)readings[0]) > 10) { + if( abs((int16_t)readings[0]) > 25) { myled3 = 1; break; } - wait(0.01); } - save.attach(&savedata, 0.01 ); + save.attach(&savedata, 0.01 ); //割り込み開始 t.start(); + + duty.write(duty_output); - while(t.read() <= 0.51) { -// debug.printf("loop sensorB\n"); + while(t.read() <= 0.80) { //内部タイマーが0.80秒に達するまで制御 if(flag) { flag = 0; controller( &v, &duty_output, &acce_device, &acce_output, &F_output); -// duty.write(duty_output); read_current( &C); -// debug.printf("duty = %f\n",duty_output); if(1) { - sprintf(buffer[i],"%f10,%f10,%f10,%f10,%f10,%f10",t.read(),C,acce_device,C,duty_output,F_output); + sprintf(buffer[i],"%f10,%f10,%f10,%f10,%f10,%f10",t.read(),C,acce_device,C,duty_output,F_output); //バッファにデータを溜めこみ終了時に吐き出す. if( i > 299) { loop_break = 1; break; @@ -127,23 +125,19 @@ } } - myled2 = 1; + + myled2 = 1; //0.80秒経過したらLED2を光らせる t.stop(); save.detach(); duty = 0.0f; - -// makefile(); myled1 = 1; for( j = 0; j < i; j++) { -// fprintf(fp,buffer[j]); - debug.printf("%s\n",buffer[j]); + debug.printf("%s\n",buffer[j]);//シリアル通信でバッファにあるデータを相手に送信する } - -// fclose(fp); - + while(1) { myled1 = 1; wait(0.2); @@ -156,14 +150,14 @@ -void savedata(void) +void savedata(void)//割り込み時の処理 { flag = 1; intrrupt_cnt++; } -void flipB(void) +void flipB(void)//フォトリフレクタの反応によって止める関数 { flipB_ = 1; duty = 0.0f; @@ -255,9 +249,10 @@ //---position reset--- dir = 0; duty = 0.50f; - while(!sensorD); + while(!sensorB); duty = 0.0f; wait(2.0); + myled1 = 1; } void controller(double *v,float *duty_output,double *acce_device, double *acce_output, double *F) @@ -271,7 +266,7 @@ static double F_1; static double F_2; static double F_3; - static int intrrupt_checker = 5; + static int intrrupt_checker = 1; //---reading acceleration and control--- @@ -284,15 +279,15 @@ F_1 = -1 * ( ka * *acce_device) + (kv * *v); *F = 0.35 * F_1 + 0.4 * F_2 + 0.25 * F_3; *acce_output = *F / 8.5; - *duty_output = *acce_output / 118 + *duty_output; + //*duty_output = *acce_output / 118 + *duty_output; if(*duty_output > 1.0) { *duty_output = 1.0; myled4 = 1; } - if(intrrupt_checker == intrrupt_cnt){ - *duty_output = *duty_output + 0.03; - intrrupt_checker = intrrupt_checker + 2; + if(intrrupt_checker <= intrrupt_cnt){ + *duty_output = *duty_output + 0.04; + intrrupt_checker = intrrupt_cnt + 1; }