加速度センサMPU6050 サンプルプログラムでは、xyz軸の加速度を表示します。

Dependencies:   mbed MPU6050 Math

Fork of MPU6050_cansat by cansat-d_2018

Files at this revision

API Documentation at this revision

Comitter:
falconsyunya
Date:
Sat Nov 24 00:01:13 2018 +0000
Parent:
6:f1106d9e843c
Commit message:
2018/11/24 9:01

Changed in this revision

MPU6050.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f1106d9e843c -r 8f914ead7fc0 MPU6050.lib
--- a/MPU6050.lib	Tue Nov 20 13:51:57 2018 +0000
+++ b/MPU6050.lib	Sat Nov 24 00:01:13 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/cansat-d_2018/code/MPU6050/#118c17d86087
+https://os.mbed.com/teams/cansat-d_2018/code/MPU6050/#51bd76211e3b
diff -r f1106d9e843c -r 8f914ead7fc0 main.cpp
--- a/main.cpp	Tue Nov 20 13:51:57 2018 +0000
+++ b/main.cpp	Sat Nov 24 00:01:13 2018 +0000
@@ -16,11 +16,13 @@
         int accel[3];//accelを3つの配列で定義。
     while(1){
         mpu.readAccelData(accel);//加速度の値をaccel[3]に代入
-        int x = accel[0];//x軸方向の加速度
-        int y = accel[1];//y軸方向の加速度
-        int z = accel[2];//z軸方向の加速度
-        float a = x^2+y^2+z^2;
-        printf("%f\r\n",a);
+        int x = accel[0]-123;//x軸方向の加速度
+        int y = accel[1]+60;//y軸方向の加速度
+        int z = accel[2]+1110 ;//z軸方向の加速度
+        float X = x*0.000597964111328125;
+        float Y = y*0.000597964111328125;
+        float Z = z*0.000597964111328125; 
+        double a = X*X+Y*Y+Z*Z-95.982071137936;
         if (a>0){
         a = sqrt(a);
         }
@@ -28,6 +30,7 @@
         a = abs(a);
         a = -sqrt(a);
         }
+        //printf("%lf %f %f %f\r\n",a,X,Y,Z);
         // ローパスフィルター(現在の値 = 係数 * ひとつ前の値 + (1 - 係数) * センサの値)
         lowpassValue = lowpassValue * filterCoefficient + a * (1 - filterCoefficient);
         // ハイパスフィルター(センサの値 - ローパスフィルターの値)//
@@ -43,7 +46,7 @@
 
         //printf(" speed %f difference %f\r\n",speed,difference);//速度と加速度を表示
         //printf("%f,",speed);//速度を表示
-        //printf("speed %f diference %f\r\n",speed,difference);//変位を表示
-        wait(0.5);
+        printf("speed %f diference %f\r\n",speed,difference);//速度と変位を表示
+        wait(0.01);
     }
 }