加速度とジャイロを100HzでSDに保存するプログラム
Dependencies: MPU6050 SDFileSystem mbed
Fork of SD_100Hz by
Revision 3:1410f9acca63, committed 2018-03-10
- Comitter:
- oichan
- Date:
- Sat Mar 10 02:39:47 2018 +0000
- Parent:
- 2:ac793e1667ec
- Commit message:
- 201803??VASE?100Hz????????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ac793e1667ec -r 1410f9acca63 main.cpp --- a/main.cpp Sun Dec 24 10:47:14 2017 +0000 +++ b/main.cpp Sat Mar 10 02:39:47 2018 +0000 @@ -5,7 +5,7 @@ #define RATE 100 //サンプリングレート[Hz] #define SAVE_NUM 100 //一度に保存するデータ数 SAVE_NUM/RATE [s]ごとに保存する -SDFileSystem sd(p11, p12, p13, p14, "sd"); +SDFileSystem sd(p5, p6, p7, p8, "sd"); MPU6050 mpu(p9,p10); Timer jikan; Ticker get_t; @@ -14,12 +14,14 @@ void _getData(); -float Data[2][SAVE_NUM][4]={0}; +float Data[2][SAVE_NUM][7]={0}; int Data_cnt = 0; bool row; int main(){ pc.printf("Hello!\r\n"); + mpu.setAcceleroRange(3); + mpu.setGyroRange(3); mkdir("/sd/mydir", 0777); bp = fopen("/sd/mydir/data.bin","ab"); //ファイルは作成は時間がかかるため先にやる fclose(bp); @@ -30,9 +32,10 @@ Data_cnt=0; row = !row; bp = fopen("/sd/mydir/data.bin","ab"); - fwrite(&Data[!row][0][0],sizeof(float),4*SAVE_NUM,bp); + fwrite(&Data[!row][0][0],sizeof(float),7*SAVE_NUM,bp); fclose(bp); } + if(jikan.read()==30.0*60.0)jikan.reset(); } return 0; } @@ -40,5 +43,6 @@ void _getData(){ Data[row][Data_cnt][0] = jikan.read(); mpu.getAccelero(&Data[row][Data_cnt][1]); + mpu.getGyro(&Data[row][Data_cnt][4]); Data_cnt++; } \ No newline at end of file