Detection of rotation

Hello guys, after a while i managed to fuse and filter smoothly the data from a mpu6050 sensor(accel & gyro). However recently i realize that my whole project had one last major problem,due to the nature of the sensors it is confused by the linear motion and as a result produces small angle measurments which actually dont exist.

For instance if i have the sensor on a table and move it linearly back and forth it results in small angles,which is wrong cause i didnt rotate it at all.

Do you know any conditions of algorithms that can help me tackle this issue, using the data or something else?

thank you.

Magnetometer, but a lot depends on how angles are small

Thanks, the angles are at a range of 2-6 degrees

I thought to put a condition like if( gyro_measurent > Threshold) it rotates
but this approach dont work as it produces constant drifts due to the filter of small changes.

Another technique i thought is that accel data follow a specific path ,when rotating one is incremented while the other decremented however they have too much noise even after a moving average

I may give magnetometer a try

Gyros drift, so you need measure the average offset during startup, keeping the sensor motionless. Subtract that offset from subsequent measurements. Repeat for each axis.

You need a magnetometer to measure the yaw angle.

euri:
Hello guys, after a while i managed to fuse and filter smoothly the data from a mpu6050 sensor(accel & gyro). However recently i realize that my whole project had one last major problem,due to the nature of the sensors it is confused by the linear motion and as a result produces small angle measurments which actually dont exist.

You have picked up on a weakness of the "complementary filter" used to detect tilt. If it experiences any lateral motion it is useless. Actually, it is useless under any conditions. There are genuine complementary filters but none have ever been discussed on this forum.

The attached pdf describes measurements I made on a balancing two wheeled robot. Lateral acceleration dominates accelerometer readings. That the accelerometer readings somehow enhances tilt measurement is nonsense.

Complementary Filter.pdf (145 KB)

That the accelerometer readings somehow enhances tilt measurement is nonsense.

Misguided comment, but no matter.

The accelerometer measures the tilt, using the acceleration of gravity to define the vertical. As the OP clearly understands, the gyro can help correct errors that accrue when gravity is not the only acceleration that the sensor is undergoing. A rate gyro alone cannot be used to measure tilt.

The best sensor fusion filter available is the Kalman and its derivatives, covered quite well in Dan Simon's excellent textbook Optimal State Estimation.

jremington:
The best sensor fusion filter available is the Kalman and its derivatives, covered quite well in Dan Simon's excellent textbook Optimal State Estimation.

I am sure the book is excellent and I am sure you have misread it.

Interesting how you conflate the complementary filter with the Kalman filter when they have nothing to do with each other.

Yes, I strongly recommend Simon's textbook. It is by far the most clearly written of the current crop, but a bit short of problem sets.

Thank you guys, i will take a look on that - this is what i was looking for

So in practice if i implement a kalman filter it could distinguish lateral motion from rotation and correct this issue?

You could try the excellent, open source RTIMUlib for Arduino, which implements a Kalman filter.

It requires a magnetometer, though for full 3D orientation.

charliesixpack:
The attached pdf describes measurements I made on a balancing two wheeled robot. Lateral acceleration dominates accelerometer readings. That the accelerometer readings somehow enhances tilt measurement is nonsense.

The document says "For dt = .010, you can rewrite this is as...
angle = .98angle + (.98gyro + 2*acc)*dt"

However, if 'dt = 0.01', then the main question is ... why is 'dt' still seen in the above equation?