I wrote a relatively simple IMU script for the mpu 6050. It takes the accel data, calculates pitch and roll, and then applies a simple low pass filter to it. I also use the gyro data to determine the gryo pitch and yaw by multiplying the angular velocity every (0.5 sec) to save calculation costs. Finally, I use a complimentary filter to calculate the final 'system' pitch and yaw. For some reason unknown to me, the imu 'freezes' (the value doesn't change) when the pitch reaches 116 degrees and/or roll reaches 175 degrees, the only thing that changes is the gyro pitch. I can't figure out why this is happening for the life of me so any help is greatly appreciated.
Connections are fairly simple. Imu VCC is 3.3v and Gnd is Gnd, SCL to SCL and SDA to SDA. Using a Arduino Mega.
Euler angles are useless at certain orientations, due to gimbal lock.
Pitch and roll, and the complementary filter, are useful only for approximately level flight, which is why the field has moved on the using quaternion-based fusion filters.
So you're saying that the lock is happening because of gimbal lock? I am converting it to quaternions later, but imo I don't think its because of euler angles since the angles vary too much for the lock up to happen.
Don't waste your time with the complementary filter. Also, one of the two equations you are using to calculate pitch and roll from the accelerometer data is incorrect.
Okay if you have any resources for directly converting to quaternion it would be helpful since I'm going from euler to quaternion because I don't know how to directly calculate quaternions from accel and gyro data. That being said, I'd really appreciate it if you could help me figure out why the imu data is freezing up like that.
You could use any of the libraries based on the Mahony or Madgwick fusion filter. There are lots of web pages describing the theory.
This one works with the MPU-6050, although since that sensor was discontinued years ago, you have some sort of clone or counterfeit, and performance probably won't meet the original specifications.
No, but there is a lot of useful information in that lecture, including one of several correct sets of equations for obtaining tilt angles from an accelerometer.
It is pointless to calculate quaternions from Euler angles without specifying which of the twelve definitions is used for the angles, regardless of gimbal lock.
I've modified my code to include the proper formulas and changed the gyro calculations, but for some reason, the accelerometer says that the imu is pitched at -14 degrees even though it has been kept on a level surface.