# What Does a Drone’s PID Controller Do?

*3D Insider is ad supported and earns money from clicks and other ways.*

Modern drones have become so easy to use that it can be easy to forget how much work goes into making them follow our commands or maintain a stable position while we take aerial photos. We have already written on how detailed articles on how drone motors and propellers work together to provide lift and propulsion, as well as on how the various sensors collect information about the drone’s surroundings. In this article, we take a closer look at the component that makes sense out of all this information: the PID controller. How does a PID controller work and what role does it play in the overall scheme of making a drone fly?

## What is a PID Controller?

A proportional-integral-derivative (PID) controller is the most common type of controller found in drones. It is a critical component in drones that provides stabilization and autonomous control. If we consider the sensors of the drone as its eyes and ears, then the PID controller is essentially its ‘brain.’ It receives information from the sensors, comes up with the appropriate response, and directs the other drone components to achieve its ‘desired’ state.

From a more practical perspective, a PID controller is basically an electrical component that receives inputs from the sensors of a drone and processes this information through a large set of algorithms. The typical set of information that a PID controller receives include the drone’s altitude, directional and angular orientation, and location. The PID controller then compares the current drone status to its desired state.

The desired state of the drone can vary according to what the drone pilot commands. For instance, a drone that is instructed to hover needs to maintain its horizontal and vertical positions and a perfectly leveled angle. Any deviations from this position will be considered ‘undesired’ which the PID controller will aim to correct. In the case of autonomous flight, the pilot may command a drone to move to a particular location or for the move to fly along a pre-determined path. This command will form the basis for the drone’s next desired parameters, and the PID controller will actively work to satisfy these conditions.

How does a drone go from an ‘undesired’ state to its ‘desired’ conditions? Through the PID controller, the drone knows exactly what it needs to do. If the drone is supposed to maintain a stable hover, any deviations from its stable position due to winds will have to be counteracted.

This is done by the PID controller sending commands to the drone’s Electronic Speed Controller (ESC), which controls the speed at which each motor rotates. This is the same process by which drones can fly from one location to another autonomously. From what we’ve discussed about drone motors and propellers, it is the variations in the speed of the rotation of the motors that allow a drone to gain altitude, make turns, and move forward and sideward.

## How does it work?

A PID controller is so-called because its algorithm combines proportional, integral, and derivative calculation methods to move from its actual state to its desired state. The ‘desired state,’ in this context, can be any parameter related to a drone’s flight performance or location: speed, altitude, location, or degree of rotation in any axis. For each of these parameters, there exists a difference between the actual value and the desired value. For example, you may be commanding your drone to fly to 100 feet while its current position is only at 60 feet. At this point, the difference between the desired and actual value (40 feet) is called the ‘error.’

Think of the PID algorithm as a single mathematical equation consisting of three terms that, when added together, combine to form the actual parameter value. In each of these terms, the error value over time is included either as a proportional, integral, or derivative factor. Each term also has a unique factor that the users can tweak while tuning.

Why does a PID controller need to use three terms? As you can imagine, the process by which the drone moves from its actual state to the desired state is not perfect. Much like trying to get the golf ball into a hole, hitting the ball too weak will land it short from your goal but hitting it too strong can also result in overshooting the goal. The three computation methods – proportional, integral, and derivative – work together to prevent this from happening.

A key concept to understanding how a PID controller works is the fact that controller response has an inherent delay. It compares the desired state of the drone with its current state even while it continues to move, meaning that the algorithm actually processes data from a few milliseconds past. This means that the actual value will tend to oscillate between positive and negative error margins before reaching the desired value. The goal of the PID controller is to reduce these oscillations so that the drone achieves its desired state as quickly as possible.

To allow the PID controller to achieve the desired state as quickly and with as little error as possible, each of the three terms has a different function:

**1.** The proportional term is simply a product of the error and an adjustable factor. By tweaking the factor, the algorithm can shorten the gap between actual and desired values. This means that the proportional term has the largest effect when the error is at its highest. As the actual value approaches the desired value, the effect of proportional term starts to diminish.

The limitation of the proportional term is that it generates a steady-state error when it is the sole controlling mechanism. The steady-state error is a product of how proportional control works; if the error is reduced to zero, then the resulting signal will also be equal to zero. Thus, the actual value ends up a little closer, but never equal, to the desired value. In our example, our drone can climb up to about 90 feet where it will hover in place, never quite reaching the 100-foot altitude that the pilot wants.

**2.** The integral term considers the accumulated error over time as the drone moves to the desired state. Much like the proportional term, the integral term also has a factor that the controller continuously tweaks as the drone moves. Note that the accumulated error that the integral term considers can either be negative or positive and that negative and positive errors cancel each other. This means that as the actual value oscillated between negative and positive error margins, the effect of the integral term diminishes.

The integral term solves the problem of the steady-state error by not reaching a zero value on the first correction attempt. This means that the controller does not stop working as the actual value approaches the desired value. In fact, it is only through repeated oscillations that the integral term eventually becomes zero. While this feature solves one problem, it creates another: by constantly overshooting the target value, it can take a really long time for the drone to become stable.

**3.** The differential term considers the rate of change of the signal’s error over time. This means that the differential term slows down the rate of correction that the controller exerts as the actual value approaches the desired value. This slows down the rate of approach to the desired value, thereby minimizing the resulting overshoot. By addressing this limitation that was brought about by the integral term, the differential term helps a controller achieve the desired value faster.

## Calibrating and fine-tuning the PID Controller

Most consumer-grade or high-end drones available today are already equipped with firmware that has been integrated with optimized PID controller algorithms. Not only do these PID controllers have pre-set factors but also have noise filtering technology to better isolate the relevant signals. With these improvement, modern drones can fly great out-of-the-box without the need to fine-tune their PID controllers.

However, we know that tinkering is an essential past-time for many members of the drone community. PID fine-tuning has been a favorite activity for DIY drone owners who want the most out of their drones. If this sounds like something you’re interested in, then you need to realize that a single set of PID parameters may not work for all drones. In fact, a single set of PID parameters will not be optimal across different flight conditions or for different drone loading requirements.

PID fine-tuning isn’t exactly complicated. After all, you will only be adjusting three factors – one each for the proportional, integral, and differential terms. However, the whole testing and checking process can take a lot of time. Many users have said that the tuning process is more an art than a science. Hitting that perfect spot where the drone can reach the desired state quickly without excessive overshooting requires a complex understanding of how the PID controller works, and usually a ton of trial and error.

Before tuning your PID, you need to make sure that your drone’s center of gravity is right in the middle. You might need to shift around some of your drone’s components to achieve this.

There are two different schools of thought with regards to the parameter values you should start with when you fine-tune your PID. Some users keep it simple and start with default values while other users choose to make a more customized approach and start at really low values. You can choose either one depending on how much time you’re willing to spend on tuning your PID and how far away from the default values you are willing to go.

Each factor in the PID controller can be adjusted individually. Start with the proportional controller and move in sequence to the integral and derivative controllers. To get the best settings, you will need to get your drone to execute swift maneuvers repeatedly. Look out for tells, such as large and repeated wobbling.

If the wobbling gets worse as you adjust the values, then correct the values in the opposite direction. If there is a considerable improvement, then keep correcting the values in the same direction. Repeat this cycle until the changes you have made no longer result in any visible improvement. At this point, you can move on to the next controller.

You can choose to employ a wide range of flight maneuvers during testing such as sudden stops, forward flight at high speeds, quick ascents, quick turns, and hovering place. Another popular method is to check for drone responsiveness at every axis – pitch, roll, and yaw – and adjust one value at a time.

Keep in mind that the process of fine-tuning a drone’s PID settings depends a lot on “feel.” There is no right or wrong way to tune your PID. There is also no set of qualifications that you can refer to when trying to determine which PID parameters are the best. It’s not unheard of for drone pilots to go back and forth between the three controllers in trying to find a combination that yields the best results. One of the most challenging goals of PID tuning is trying to find a set of parameters that is robust – meaning that it can work across different flight circumstances.

## Final thoughts

Along with our articles on how drone motors, propellers, and sensors work, we are starting to build a complete picture of how drones work. In this article, we tackle the brain of the drone – the PID controller. With this controller, the drone can receive the input from its various sensors and move the drone from its actual state to the desired state. The PID controller is essential in allowing a drone to maintain stability or to move autonomously.

While modern drones already have perfectly tuned PID controllers, custom PID fine-tuning remains a very popular activity among the drone community. With proper tuning, you can give your drones that extra “oomph” – an improvement that can make your drone perform better according to your flight style. Tuning your drone’s PID controller is actually a simple process as long as you understand the fundamentals of how the controller works. How about taking it for a spin over the weekend?