あの装置用
Dependencies: ADXL345_I2C QEI SDFileSystem mbed
Revision 8:9059f95fc498, committed 2017-03-24
- Comitter:
- ojityan
- Date:
- Fri Mar 24 07:03:37 2017 +0000
- Parent:
- 7:0e3fac3c6a6a
- Commit message:
- ???
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0e3fac3c6a6a -r 9059f95fc498 main.cpp --- a/main.cpp Sun Mar 05 18:48:04 2017 +0000 +++ b/main.cpp Fri Mar 24 07:03:37 2017 +0000 @@ -1,7 +1,5 @@ #include "mbed.h" -#include "SDFileSystem.h" #include "ADXL345_I2C.h" -//#include "QEI.h" #include <stdio.h> #include <stdlib.h> @@ -18,7 +16,6 @@ PwmOut duty(p24); I2C i2c(p28, p27); -SDFileSystem sd(p11, p12, p13, p14, "sd"); ADXL345_I2C accelerometer(p9, p10); Serial debug(USBTX,USBRX); //QEI wheel (p21, p22, p23, 1000); @@ -99,19 +96,19 @@ break; } } - save.attach(&savedata, 0.01 ); //割り込み開始 + save.attach(&savedata, 0.01 ); //割り込み開始 t.start(); duty.write(duty_output); - while(t.read() <= 0.80) { //内部タイマーが0.80秒に達するまで制御 + while(t.read() <= 0.80) { //内部タイマーが0.80秒に達するまで制御 if(flag) { flag = 0; controller( &v, &duty_output, &acce_device, &acce_output, &F_output); read_current( &C); 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; @@ -126,7 +123,7 @@ } - myled2 = 1; //0.80秒経過したらLED2を光らせる + myled2 = 1; //0.80秒経過したらLED2を光らせる t.stop(); save.detach(); @@ -157,56 +154,26 @@ } -void flipB(void)//フォトリフレクタの反応によって止める関数 + +void ADXL_config(void)//ADXL345の初期設定 { - flipB_ = 1; - duty = 0.0f; - debug.printf("flip sensorB!"); - __disable_irq(); -} - -void ADXL_config(void) -{ - //Go into standby mode to configure the device. + //初期設定開始 accelerometer.setPowerControl(0x00); - //Full resolution, +/-16g, 4mg/LSB. + //精度 accelerometer.setDataFormatControl(0x0B); - //3.2kHz data rate. + //3.2kHz accelerometer.setDataRate(ADXL345_3200HZ); - //Measurement mode. + //計測開始 accelerometer.setPowerControl(0x08); accelerometer.setOffset (0, 0); } -void makefile(void) -{ - char filename[100]; - int num; - //---SDsetting-- - mkdir("/sd/mydir", 0777); - for(num=1; num<=256; num=num+1) { - sprintf(filename,"/sd/mydir/data%d.csv",num); - fp = fopen(filename, "r"); - if(fp == NULL) { - fp = fopen(filename,"w"); - debug.printf("file number is %d.\n",num); - break; - } - fclose(fp); - debug.printf("data%d exists\n",num); - } - -// fprintf(fp,"Time,Current,acce_device,v_device,duty_output\n"); - -// fprintf(fp, "Hello fun SD Card World!\n"); -} - -void INA226config(void) +void INA226config(void) //INA226の設定 { char p_addr = 0x00; @@ -216,7 +183,7 @@ //---ammeter setting--- i2c.start(); if(i2c.write(i2c_addr | 0,&p_addr,sizeof(p_addr)) == 0) { - debug.printf("DA-ME-DA-YO!\n"); + debug.printf("ERROR_write\n"); } debug.printf("OK!\n"); @@ -244,7 +211,7 @@ } } -void weight_init(void) +void weight_init(void) //慣性力発生用のおもりの位置の初期化 { //---position reset--- dir = 0; @@ -255,7 +222,7 @@ myled1 = 1; } -void controller(double *v,float *duty_output,double *acce_device, double *acce_output, double *F) +void controller(double *v,float *duty_output,double *acce_device, double *acce_output, double *F)//制御部 { double ka = 100; @@ -269,22 +236,21 @@ static int intrrupt_checker = 1; -//---reading acceleration and control--- +//---加速度を読み取り変換する--- accelerometer.getOutput(readings); *acce_device = (int16_t)readings[0] * 0.0383; -// debug.printf("acce_device = %f\n", *acce_device); *v = *v + *acce_device * 0.01; if( *acce_device < 0) { if(abs(*v) > 0) { +//---必要な力の算出(今回は不使用)--- 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; if(*duty_output > 1.0) { *duty_output = 1.0; myled4 = 1; } - +//---加速度を検知したら慣性力発生用おもりを加速させる--- if(intrrupt_checker <= intrrupt_cnt){ *duty_output = *duty_output + 0.04; intrrupt_checker = intrrupt_cnt + 1; @@ -292,15 +258,14 @@ duty.write(*duty_output); -// duty.write(1.00); + F_3 = F_2; F_2 = *F; -// debug.printf("%i,%f,%f\n", (int16_t)readings[0],*v,*duty_output); } } } -void read_current(double *C) +void read_current(double *C) //電流量を測る { char I[2]; unsigned short read_item; @@ -318,5 +283,4 @@ *(d_p + 0) = *(s_p + 0); *(d_p + 1) = *(s_p + 1); *C = static_cast<double>(d_s) /* * 1.25 */; -// debug.printf("%f\n",*C); } \ No newline at end of file