Hello everyone, I have been recently trying to make my own IMU using a 9DOF sensor that accurately gives 360 degree coverage. I have found that trying to use trigonometry to integrate the sensor's angles together results in Gimbal lock. The other option I have heard of is using Quaternions to represent an objects 3D orientation. But then there's the problem of how you use the Quaternions in a PID loop to control movement. You could transform the Quaternions into Euler angles so that the PID loop could work as it was designed to, but doesn't that just reintroduce the problem of Gimbal lock? And how do you even take the raw data from the threes sensors and combine and transform the measurements into Quaternions? Also, do you need to first turn the raw data into Quaternion units? I know that you can purchase a BNO055 Adafruit board, which has an algorithm chip integrated on it so that it can output Quaternion results, but it costs 30$ compared to a 5$ alternative of just buying the GY-521 and the GY-273 (which is the setup I have) which just outputs raw data. Any help on the matter would be most appreciated.
If you have any clarifying questions, please feel free to ask them.
That is what just about everyone does these days.
Arduino sensor fusion libraries implementing the Mahony (my favorite), Madgwick and Kalman filters, using a quaternion to represent orientation, are available for all modern 9DOF sensors on the hobby market.
I don't know of any Arduino libraries that implement PID attitude control based on quaternions, but that is also standard practice for professionals. You should have no problem finding papers that describe how to implement the control algorithm in detail.
So its possible to turn the raw data from the gyro (degrees a second), accelerometer (g's) and the magnetometer (gauss) into Quaternions? I want to be able to make my own code without using any library's so that I can fully understand whats happening. Where should I begin this complex process?
Not only is it possible, that is exactly what the Mahony, the Madgwick and the Kalman fusion filters are designed to do, and all of them are currently used in model equipment like drones, aircraft, boats and cars.
The basic math for the different filters is reviewed here (among other sites): OlliW's Bastelseiten ยป IMU Data Fusing: Complementary, Kalman, and Mahony Filter
Thank you very much for your help.