简体   繁体   中英

How do I calculate tilt angle from mpu6050?

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 ie angle += Gx*590; //END when 1 second is complete

Will this give me correct angle? Does the self balancing robot tilt in Gx direction?

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 :

  • Kalman filter: hard to understand but reliable when implemented properly
  • Madgwick's algorithm : easier to implement, but less reliable

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM