Image source: https://x-io.co.uk/downloads/madgwick_internal_report.pdf
In order for our bi-copter to be stabilized in the first place, it needs to know its orientation. This is the purpose of our 9-axis inertial measurement unit (IMU), which
consists of an accelerometer, gyroscope, and magnetometer. In the real world, unprocessed IMU data is unreliable, with issues such as noise and drift, making it unpractical to
work with. A solution to this is sensor fusion by algorithm, such as using a complimentary filter. A complimentary filter is a simple method that combines accelerometer
and gyroscope data to estimate orientation. It does this by blending high-pass filtered gyroscope data with low-pass filtered accelerometer data using a single weight
coefficient, providing a more accurate and reliable result than either sensor would individually. However, with its simplicity comes with some problems, a major one
being gyroscope drift, which makes it less than ideal for our application. Another algorithm would be the Kalman filter, which estimates the state of a dynamic system by
combining predictions from a mathematical model with noisy measurements, using probabilities to minimize uncertainty and optimally update the state with each new observation.
However, it is difficult to implement, requiring a sophisticated model of the system, as well as being computationally expensive, which our microcontroller would not be able
to run at a practical speed.
We ultimately chose to implement the Madgwick filter for orientation estimation. This algorithm employs a quaternion to describe the coupled nature of orientations in three-dimensions and
is not subject to the problematic singularities associated with an Euler angle representation. The use of quaternions allows accelerometer and magnetometer data to be used in an analytically
derived and optimized gradient-descent algorithm to compute the direction of the gyroscope measurement error as a quaternion derivative, allowing for the estimated angular rate of
change to be more accurate, leading to more accurate orientation estimations once integrated. Its main advantages over previously mentioned filtering algorithms is that it is easy to implement,
only requiring a single tunable parameter for optimal performance, produces reliable orientation estimations, has inherent gyroscopic drift compensation due to constant corrections, and is computationally cheap.
With this reliable orientation data, our control loop is now able to generate proper motor and servo responses to achiever stabilization.