User Tools

Site Tools


embedded:adventures:quaternions

Quaternions are an alternative way to express three-dimensional angles. Essentially, q = w + xi + yj + zk, with q being the quaternion.

Euler angles are your standard X, Y, and Z planes, and transforms in those planes occur just as you would expect them to.

When we were working with the IMU/gyro, there was a need to use quaternions to avoid the issue of gimbal lock. Gimbal lock occurs when two axes, during rotation, merge (align perfectly) and rotate each other. If the X and Y axes merged, and we performed a Y rotation, the X axis would rotate as well, which is not unexpected and undesirable. This can produce significant errors in measurement.

To implement this with the IMU and mBed, we had to use an alternative set of quaternion equations that used the angular velocity of each axis, which is the IMU output. They are shown below:

delta(q) = cos(mag(w)*delta(t)) + normal(w)*sin(mag(w)*delta(t))

delta(t) is the time interval between each measurement update from the IMU.

We used a timer handler, which runs independently of the main loop, to perform quaternion calculations. We found that 20 microseconds was sufficient to update the angles. In order to debug our implementation, we had to convert the quaternion back into Euler angles, which is not the most reliable method. A better way would be to use the IMU measurements to rotate an arm on a Terrabot and look for any unexpected movement (produced by gimbal lock).

embedded/adventures/quaternions.txt · Last modified: 2023/03/06 10:31 by 127.0.0.1