QUATERNIONS IN EULER-CONSTRICTED ENVIRONMENTS
INTRODUCTION
Euler angles are pitch, roll, and yaw. They are simple and easy to understand. They describe how an aircraft rotates about it’s center of gravity as shown in the NASA diagram below.
THE PROBLEM
Unfortunately, Euler angles encounter a problem known as gimbal lock. Gimbal lock is where two or more of the axis rotate in such a way as to prohibit them from working correctly. The video below shows how scientists on the Apollo 13 encountered this issue and how they overcame it:
QUATERNIONS
To solve this issue graphics engines use a rotation system based in 4 dimensions, which are called quaternions. While it would be nice to use quaternions directly to control the movement of the space shuttle (or our flight simulator), this is not possible. We are constrained by movement in 3 dimensional space. Therefore, because we cannot rotate our flight simulator using Quaternions, it has to be converted back to Euler coordinates in order for the movement to be processed.
The space shuttle solved this problem by incorporating a 4th axis that was always driven 90-degrees out of phase with the other three to ensure that the entire gimbal can never lock. We’ve developed a framework for expressing quaternion rotations into Euler coordinates in software, specifically for a 2 DOF (Degree of Freedom) 360-degree capable motion platform. The source code is below:
GitHub Repository
Click below to access my public repo for Quaternion to Euler conversions. I’ve spent hundreds of hours coming up with this solution, I sincerely hope that you find it helpful.
I’ve included a unit test library with the code that has been tested with Unity 2019.2.18f1. It'll likely work on other versions of Unity but I haven't checked.
RELATED PAPERS
We have a paper targeted for the IEEE Human-Machine Systems which is outlining our solution to this issue.