I build a self-balancing robot, at least that what i should have been. now i have tried implementing a complementary filter which combines gyro and accelerometer data, but the problem is that the motor and the IMU (MPU 6050) are on the same board and max. an inch away from each other.
So, if i get it right, the vibrations from the Motor do influence the accelerometer way to much, hence i am not getting any applicable result when the robot is set to the ground.
So, what techniques can i apply to get the absolute orientation?
This, right now, is my code with the complementary filter. My problem is, that even when the motor is off, the yAngle value varies very much from the yAcc value, although the yAcc value is correct. Is there any error in my code causing the gyro drift to break the whole filter?
// 100.0 is dt, 14.375 the gyro-specific resolution float gyroY = (float)(readY()) / 14.375 / (100.0); int z = getAccZ(); int x = getAccX(); float yAcc = atan((float)z / (float) x) / PI * 180; yAngle = 0.98 * (yAngle + gyroY) + (0.02 * yAcc);