Programming an Embedded Quadcopter Flight Controller

Position Measurement

In order to fly, every multirotor aircraft must be able to determine how to move from its current position to the desired location. To do this, the device must be able to figure out its orientation in space. This is typically done using two specific components, an accelerometer and gyroscope.

In some instances, a multirotor may be able to fly using the gyroscope alone; however, this functionality requires increased attention from the pilot to ensure the device does not crash.

The process of taking an action based on observations is known as a feedback loop. You experience this every day when you get in the shower and turn down the temperature when the water is too hot or turn down the volume on the TV because it is too loud. In these scenarios, you are making observations using your senses and reacting to suit your preferences. Similarly, the quadcopter performs the same types of reactions using its own inputs and sensors. These inputs may come from the pilot, controlling the quadcopter to avoid crashing, or from data and measurements that are taken by the device, in which case the programmer indicates what the quadcopter should do in certain scenarios.

The accelerometer is the key component that allows for a multirotor fly autonomously— without the need for input from a pilot or other sensor. As the name would imply, this device measures acceleration by calculating the strength (or magnitude) of any force that acts upon it.

Animation showing the graph of an accelerometer output over time

The notable advantage provided by an accelerometer is that it can tell us what direction is down because gravity will always be pulling the device towards the ground. This allows us to describe the orientation of the quadcopter using some basic trigonometry.

This is the same concept used by smartphones to flip the screen when they are turned. The device can measure the force of gravity and turn the screen so that it is perpendicular to the direction.

The data from the accelerometer and gyroscope may be combined in order to ensure the accuracy of the measurements.

Using this data from the onboard sensors (in combination with commands from the remote) the quadcopter is able to adjust the speed of its motors in order to change location.