Modified 2020-09-03 by Rara Ma
Here is a helpful intro video explaining PID controllers
Modified 2020-09-03 by Rara Ma
The Proportional Term
The proportional term produces an output that is proportional to the calculated error:
During programming, you would represent this as:
The magnitude of the proportional response is dependent upon which is the proportional gain constant. A higher proportional gain constant indicates a greater change in the controller’s output in response to the system’s error.
The propellers will spin faster the farther away the drone is.
The Derivative Term
The derivative term is determined by the rate of change of the system’s error over time multiplied by the derivative gain constant .
In terms of calculus, it would be represented like this:
In terms of programming and without the use of calculus, it can be represented by:
The derivative term will do something like: propellors will spin slower the faster the drone is moving. Or a similar example is when drag is pulling harder, the faster the drone is moving.
The Integral Term
The integral term accounts for the accumulated error of the system over time. The output produced is comprised of the sum of the instantaneous error over time (or simply the instant rate of change in the error) multiplied by the integral gain constant .
In terms of calculus, the equation would look like this:
With no calculus, the equation would look like this:
The integral term will do something like: propellors will spin faster the longer the drone is away from the desired set point.
Modified 2020-09-03 by Rara Ma
The overal control function consists as the sum of proportional, integral, and derivative terms.
The figure below summarizes the inclusion of a PID controller within a basic control loop.
Modified 2020-09-16 by Rachel Ma
Tuning a PID controller is done by setting the conotrl parameters to values that fit to be able to get an ideal control response. The three control terms may be correlated and so changing one parameter may impact the influence of another. The general effects of each term are therefore useful as reference, but the actual effects will vary depending on the specific control system.
Modified 2020-09-16 by Rachel Ma
In this part of the project, you will be implementing a PID controller for a simulated drone that can only move in one dimension, the vertical dimension. You can control the speed the motors spin on the drone, which sets the thrust being generated by the propellers. In this system, the process variable is the drone’s altitude, the setpoint is the desired altitude, and the error is the distance in meters between the setpoint and the drone’s altitude. The output of the control function is a PWM (pulse-width modulation) value between 1100 and 1900, which is sent to the flight controller to set the drone’s throttle.
To run the simulation, you need to use the vnc server. You can find the installation link here.
Run sudo vncserver
.
With bash, navigate to the file named drone_simulator, which is located within the scripts folder of pidrone_pkg-master folder.
You should implement the discretized version of the PID control function in student_pid_class.py:
Notice that there is an extra offset term added to the control function. This is the base PWM value/throttle command before the three control terms are applied to correct the error in the system.
To tune your PID, set the parameters () in z_pid.yaml.
To test your PID, run python sim.py
on your base station or a department computer but not on your drone, since it requires a graphical user interface to visualize the output. The PID class in student_pid_class.py will automatically be used to control the simulated drone. The up and down arrow keys will change the setpoint, and r resets the simulation.
You will need numpy, matplotlib, and yaml to run the simulation. To install these dependencies, run pip install numpy matplotlib pyyaml
.
Effects of :
Increasing will proportionally increase the control output. This causes the system to react more quickly (thereby decreasing the rise time and the settling time by a small amount). Even so, setting the proportional gain too high could cause massive overshoot, which in turn could destabilize the system. Increasing also has the effect of decreasing the steady-state error. However, as the value of the process variable approaches the setpoint and the error decreases, the proportional term will also decrease. As a result, with a P-controller (a controller with only the proportional term), the process variable will asymptotically approach the setpoint, but will never quite reach it. Thus, a P-controller cannot be used to completely eliminate steady-state error.
Effects of :
The integral term takes into account past error, as well as the duration of the error. If error persists for a long time, the integral term will continue to accumulate and will eventually drive the error down. This has the effect of reducing and eliminating steady-state error. However, the build-up of error can cause the value of the process variable to overshoot, which can increase the settling time of the system, though it decreases the rise time.
Effects of :
By calculating the instantaneous rate of change of the system’s error and using this slope for linear extrapolation, the derivative term anticipates future error. While the proportional and integral terms both act to move the process variable to the setpoint, the derivative term seeks to dampen their efforts and decrease the amount the system overshoots in response to a large change in error (which would greatly affect the magnitude of the proportional and integral contributions to the overall control output). If set at an appropriate level, the derivative term reduces oscillations, which decreases the settling time and improves the stability of the system. The derivative term has negligible effects on steady-state error and only decreases the rise time by a minor amount.