PID Controller Tuning for a Drone
The program in the DIY Mini Drone: Arduino™ Altitude Control project uses a proportional controller to control the drone's altitude. A potentiometer is connected to one of the Arduino's analog inputs. The potentiometer sends an adjustable voltage to the Arduino, and the code converts this voltage to a target height. An ultrasonic distance sensor measures the actual height, and the code subtracts this from the target height to compute an error. It then increases or decreases the motors' speed by an amount that is proportional to this error, in order to move the drone back toward the target height and decrease the error. The factor multiplied by the error is called the controller's "gain." In this case, the control signal is a pulse-width modulation (PWM) signal sent to the motors using the Arduino analogWrite() function. Since the PWM signal must be a non-zero value to make the drone hover at a fixed height, the control signal also includes a bias term, and is calculated using this equation:Equation 1:
While proportional controllers are very simple, they have one major limitation. They are subject to a steady-state offset error, meaning the drone will never actually reach the exact target height. While you can decrease the offset error by increasing the controller's gain, this can have undesired side effects like rapid, jerky motion of the drone, and you can never eliminate the error entirely with a purely proportional controller.
You can solve this problem by using a proportional-integral (PI) or proportional-integral-derivative (PID) controller. As the names imply, these controllers also change the motor speed by amounts that are proportional to the integral and/or derivative of the error. A PID controller has three gains: KP, KI, and KD. The control signal is calculated with the equation (note that technically a PI controller is just a PID controller where KD=0):Equation 2:
The process of selecting the gain values for Equation 2 is called "tuning" the controller. A properly tuned controller will give the drone a response that is "just right," meaning that it will quickly return to the target height (this is called the "rise time"), without too much overshoot, oscillation (the "settling time"), or steady-state error. A poorly tuned controller can result in undesired or erratic drone behavior, like moving very slowly toward the target height, or rapidly shooting past it, then over-correcting and shooting past it again, etc.
Can you design a PID controller for your drone that results in optimal behavior? You may need to do some of your own research about PID controllers to get started. The Bibliography contains several references that may be useful. Refer to DIY Mini Drone: Arduino™ Altitude Control for instructions to build your drone. The circuit diagram is reproduced in Figures 1 and 2, and you can download working code for a proportional controller here. (Click these links for a bigger version of the diagram and the circuit schematic.)
Figure 1. Breadboard diagram for Arduino drone controller.
Figure 2. Circuit schematic for Arduino drone controller.
Cite This PageGeneral citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.
Last edit date: 2021-03-10
- National Instruments. (2020, March 17). PID Theory Explained. Retrieved March 2, 2021.
- Wikipedia Contributors. (n.d.). PID Controller. Retrieved March 2, 2021.
- Cook, J. (2019, November 1). PID Controller Basics & Tutorial: PID Implementation in Arduino. Retrieved March 2, 2021.
Ask an ExpertThe Ask an Expert Forum is intended to be a place where students can go to find answers to science questions that they have been unable to find using other resources. If you have specific questions about your science fair project or science fair, our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.
Ask an Expert
If you like this project, you might enjoy exploring these related careers:
Looking for more science fun?
Try one of our science activities for quick, anytime science explorations. The perfect thing to liven up a rainy day, school vacation, or moment of boredom.Find an Activity
Explore Our Science Videos
Make a Hygrometer to Measure Humidity - STEM activity
How to Make an Electromagnet
Fire Snake Experiment