Combining accelerometer and gyroscope data.

Hi all,
I'm searching on web aboyt how to combining accelerometer and gyroscope data and I found this:

"

First you need to integrate the output from the gyro to get the actual X, Y and Z angles.

angleX = gyroAngleX + gyroInputX
angleY = gyroAngleY + gyroInputY

However this value will drift over time so you will need to use a complementary filter or kalman filter. Personally, I would recommend a complementary filter because it is much simpler to implement.

First you must find the angle from the accelerometer using a little bit of trigonometry.

accelAngleX = atan2(accelY, accelZ) * 180/M_PI;
accelAngleY = atan2(-accelX, sqrt(accelY*accelY + accelZ*accelZ)) * 180/M_PI;

Then get the actual angle using this formula.

angleX = 0.98*angleX + 0.02*accelAngleX
angleY = 0.98*angleY + 0.02*accelAngleY

The variables above must be the same variables used when calculating the gyro angle. The 0.98 and 0.02 can be tuned to get the best output, but they should always add up to one.

"

but I can't understand these lines:

angleX = gyroAngleX + gyroInputX
angleY = gyroAngleY + gyroInputY

what gyroAngleX and gyroInputX are.
If anyone know please help.
Thanks!!

Regardless of what those variables were intended to mean, the comment and associated code is wrong.

Gyros output the rate of rotation. When a particular rate gX in degrees/sec is measured during time interval dt seconds, the total estimated change in the X angle is gX*dt degrees.

You have to know the time interval dt and also the scale factor associated with the output units of the gyro you are using in order to estimate total degrees rotation. Check the gyro data sheet for the details.

Thanks for your reply.
Also how I could calculate degrees/sec I have mpu9250 sensor which is a digital sensor

The MPU9250 datasheet will provide the details.

I found a way to calculate deg/sec but first I need to turn digital data into analog (voltage).
How I could succeed this?\

With a digital to analogue converter?

Yes with digital to analoge converter but how I could do it on c++
Which is the code for this?

DimitrisTzam:
Yes with digital to analoge converter but how I could do it on c++
Which is the code for this?

DACwrite (digitalValue);

I found a way with low pass filter

I'm new on programming so could you explain me this function?