Initially, the methodology to calculate the desired joint angle is as follows: simply integrate the accelerometer data twice, and integrate the gyroscopic data once (as gyroscope yields angular rate). However, upon doing this, we realized that the data/plots were inaccurate. This is because when integrating, the noise is also added (oops). Numerous filters were designed to overcome this complication, but to no avail. Instead, other calculations were calculated instead: Yaw, Pitch, and Roll. These measurements proved to be much more useful, and accurate.

Yaw, pitch, and roll are common values used in aerodynamics, used to stabilize planes, quadcopters, or anything of this sort. The three dimensional axis are shown below. Since we are moving across the X-Y axis, we will be using yaw to measure our joint angle; yaw is the rotational movement around the Z axis, as shown in the figure below.

The math behind this is Euler angles, which define the orientation of a rigid body with respect to a fixed three-dimensional axis. This means that there will be two defined three dimensional axis, one which moves with respect to the sensor, and one that does not move (the rigid axes). The moving axes shall be compared to the rigid axes in order to calculate the angle, giving us our yaw, pitch, and roll values. However, there is a fundamental mathematical problem of Euler angles, called gimbal lock. Basically, the pitch angle is limited from -90 degrees to positive 90 degrees. Once this occurs, the data behaves in a very wild and erratic manner. Of course, the arm may move past +-90 degrees, so we decided not to go with this. Another method to calculate the yaw, pitch, and roll angles are was implemented, utilizing matrices, known as quaternions. Quaternions are much more accurate, and do not have any sort of limitation as described by the Euler angles.

After implementing the math behind the quaternions, the data was accurate! Furthermore, it was received in real time, with a little bit of a time lag present. Currently, we are working on reducing this time lag.