Reputation: 63
I am building a self-balancing robot and I have managed to configure the gyroscope mpu6050 and I now have six readings Ax,Ay,Az and Gx,Gy,Gz. My question is how do I calculate tilt angle from both Ax,Ay,Az and Gx,Gy,Gz?
Here is what I know so far, kindly correct me if I am wrong:
I can calculate the force of Gravity in G's measured in horizontal position as Ax=Ay=0 and Az=1. I use this to find tilt angle as angle_accel = arctg( Ay / sqrt( Ax^2 + Az^2 ) )
. But I am not sure if my tilt is in Ay direction or not?
I can get the Gyro angle through integration. My gyro is read (Gx) 590 times in a 1 second period.
float angle; //gyro angle angle = angle + Gx; //sum 590 times i.e angle += Gx*590; //END when 1 second is complete
Will this give me correct angle? Does the self balancing robot tilt in Gx direction?
Upvotes: 2
Views: 3799
Reputation: 3605
In a perfect world, you could integrate twice the angular acceleration. But it practice, there is an important drift: it's not working properly.
The only working solution is merging data from accelerometer, gyroscope and magnetometer. This is what we call AHRS. There is two working solutions :
On this page, you will find an implementation (source code and example) with an MPU-9250 which is the big brother of your MPU-6050
Upvotes: 1