Programming an Embedded Quadcopter Flight Controller

Control Loop

The control loop is the brains of the operation, responsible for collecting all of the information from the remote and gyro and converting it into commands to tell the motors how fast to spin. 

The type of control loop that is used in this project is known as a “feedback loop.” This type of program attempts to improve itself over the course of the flight based on observations of its own performance. The most common type of feedback loop used for quadcopters and many other devices is known as a PID controller.

In this type of algorithm, two values are compared to compute a number is known as the “error”. This information is used by the PID controller to figure out how much it needs to adjust the system in order to get rid of the error. For a quadcopter, the two values used to compute the error are the current orientation of the device and the input from the remote. 

The PID controller in itself is a combination of three separate components, a proportional, integral, and derivative controller, abbreviated as P, I, and D respectively.

The three controllers in the PID loop perform calculations using the same information; but, they analyze the data in different ways to understand the quadcopter’s movement. The results of these predictions are then combined to determine the action that the quadcopter should take in order to arrive at the desired position. The output from this algorithm helps to inform how the device should adjust the speed of the motors in order to move to the desired position.

The proportional controller tells the quadcopter how to move based on what is currently happening with the system. Unfortunately, this can cause the quadcopter to keep moving past— or overshoot— the desired location as it cannot account for the past or future motion.

This is where the integral and derivative are used, in order to help compensate for the “overshoot” that is produced by the proportional controller.

The integral analyzes the cumulative error over time. This tells the program how much error has been unaccounted for and still needs to be corrected.

Finally, the derivative keeps track of how quickly the error is changing. This is done by recording the last value and comparing it with the current value in order to determine the rate of change. This helps to compensate for scenarios like the ones described above, before the desired location is passed, to prevent further overshoot.

When properly tuned, the P, I, and D controllers should behave in a similar manner, as shown above, reaching an equilibrium. While none of the individual values initially reach the desired reference, by using the controllers in combination, the program eventually reaches this steady-state.

This same pattern of overshoot (which results in a back-and-forth oscillation) can be seen directly in the flight of the quadcopter in the process of tuning as seen in the videos below.

In the above circumstances, it is easy to see the overshoot or wobble that is produced by the proportional controller in the PID algorithm. As the tuning gets more precise the oscillations become less apparent.