Reputation: 664
I try to get the Z-angle rotation of a GY-521 ( MPU 6050 ) but the angle rise static also if i don't move the sensor. Is there a way to "filter" the angle that he is correct for my case ?
Code:
float accel_z = accel_t_gyro.value.z_accel;
float accel_angle_z = 0;
float gyro_angle_z = gyro_z*dt + get_last_z_angle();
float unfiltered_gyro_angle_z = gyro_z*dt + get_last_gyro_z_angle();
float alpha = 0.96;
float angle_z = alpha*gyro_angle_z + (1.0 - alpha)*accel_angle_z;
output when sensor not moved:
x = x-roatation-angle z = z-roatation- angel
x z
8.37 4.24
8.35 4.22
8.33 4.21
8.32 4.19
8.31 4.18
8.29 4.17
8.28 4.15
8.26 4.14
8.25 4.12
8.23 4.12
8.22 4.10
8.21 4.09
8.19 4.07
8.18 4.05
Upvotes: 1
Views: 7504
Reputation: 876
Timo, I saw that you found a partial solution to your problem (quote: "there is no gravity that hold the gyroscope in the right position"). I would like to elaborate because there are ways to get reasonably good results from a gyroscope only. I don't know if it will be good enough for your application. Here are the results I got using the same hardware as you: http://robokitchen.tumblr.com/post/68625623585/imu-with-gyroscope-only-i-tested-the-three-axes. In this video I am not using the accelerometer at all.
There are two points that could help you get better results:
1) Unless your sensor remains totally horizontal you cannot get the z-axis rotation using this formula:
float gyro_angle_z = gyro_z*dt + get_last_z_angle();
To explain why, imagine this: if your gyroscope turned 90 degrees around the x axis then 90 degrees around the z axis, you would not obtain the same result as if it only turned 90 degrees around the z axis. This means that you should compute the rotation around all the axes and then extract the z-axis rotation. If you don't use the x and y axes your results will be incorrect (unless your sensor remains totally horizontal).
One efficient way to compute the rotation around all the axes is to use quaternions. There is a lot to say about quaternions, so I let you do your own research and ask more questions if required.
2) After using all the 3 axes there will still be a static drift. This is because the gyroscope will not read a perfect 0 even when it does not move. To improve the situation, you could calibrate the gyroscope. An easy way to calibrate is to read a large number (100+) of values when the gyroscope is not moving, calculate the average drift, and subtract it from your measures when the gyroscope is moving. There will still be a slight drift after this, but not as bad as what you may be experiencing now.
Here are the best results I got, using the MPU-6050 gyroscope and accelerometer: http://robokitchen.tumblr.com/post/68626551378/imu-with-gyroscope-and-accelerometer-i-ran-the. As you already know the accelerometer helps stabilise the x and y axes but not the z axis. However the z axis drift is low and remains useable for many applications. For instance there are several quadcopters which do not use a magnetometer and suffer from z axis drift and yet remain useable.
Upvotes: 1