Hardware Reference
In-Depth Information
Chapter 7
PID Controllers
Proportional-Integral-Derivative (PID)
is a cornerstone algorithm in control theory. The PID algorithm smoothly and
precisely controls a system, such as temperature in an oven or the position of a control surface on an airplane. A PID
controller works by calculating an amount of error based upon the difference between a set value and a feedback
value, and provides an adjustment to the output to correct that error. The control and decision of the adjustment is
done in math instead of pure logic control such as
if...else
statements. PID controllers have many types of uses,
including controlling robotics, temperature, speed, and positioning. The basics, coding setup, and tuning of PID
controllers for the Arduino platform are discussed in this chapter.
The Mathematics
Setting up a PID controller involves constantly calculating an algorithm. The following equation is the sum of the
three parts of PID:
proportional
,
integral
, and
derivative
. The equation for the PID algorithm attempts to lower
the amount of difference between a setpoint (the value desired) and a measured value, also known as the
feedback
.
The output is altered so that the setpoint is maintained. PID controllers can easily work with systems that have
control over a variable output.
The variables of the equation are
E
: The calculated error determined by subtracting the input from the setpoint (
Sp - Input
)
•
t
: The change in time from the last time the equation has run
•
Kp
: The gain for the proportional component
•
Ki
: The gain for the integral component
•
Kd
: The gain for the derivative component
•
The Proportional Statement
The
P
in
PID
is a proportional statement of the error, or the difference between the input and the setpoint value.
Kp
is
the gain value and determines how the P statement reacts to change in error; the lower the gain, the less the system
reacts to an error.
Kp
is what tunes the proportional part of the equation. All gain values are set by the programmer or
dynamically via a user input. The proportional statement aids in the steady-state error control by always trying to keep
the error minimal. The
steady state
describes when a system has reached the desired setpoint. The first part of the
proportional code will calculate the amount of error and will appear something like this:
error = setpoint - input ;