1. PID Controllers
Pieter PTable of Contents list
This first chapter gives a brief recap of PID control theory. It describes the controller architecture and derives the formulas that will be implemented in C++ in the next chapter.
Prerequisites: basic control theory, Laplace and Z-transforms.
Continuous-time
In this first section, we'll assume that all signals are functions of a continuous time variable
Closed-loop controllers
Figure 1 shows the block diagram of a general closed-loop or feedback control system.
The output
The PID controller
In a PID controller, the control signal is calculated as the sum of three components: a proportional component,
an integral component, and a derivative component. The proportional component simply multiplies the error
by a constant
The block diagram of this type of controller is shown in Figure 2.
You can find intuitive explanations of the purpose of each of the three components all over the internet, but in short: the proportional component makes the controller act on the instantaneous error, the integral component accumulates past errors in order to minimize the steady-state and tracking error, and the derivative component penalizes the velocity at which the output changes, which can help to reduce overshoot.
Frequency domain
In the frequency or
Derivative filtering
The derivative of the error can be rather noisy, so practical PID controllers
often include a low-pass filter. Let
For the sake of simplicity, we'll use a single-pole low-pass filter to
filter the error before taking the derivative. The transfer function of this
filter is
Discrete-time
Since computers and microcontrollers cannot deal with continuous time, the
control law has to be discretized. We'll use
Discrete-time signals
Given the continuous-time error signal
We will use the same letters for continuous-time and discrete-time transfer functions and
signals in the
Forward Euler
The first discretization method we'll have a look at is the forward Euler method, it is one of simplest methods available to approximate a continuous-time ordinary differential equation by a discrete-time difference equation or recurrence relation.Integral
When the time step
This signal
In the
Backward Euler
The backward Euler method
is very similar to forward Euler, but
it has a different time delay:
When applied to the derivative
Derivative
We can approximate the derivative term in the control law using
finite differences:
In the
In the
Low-pass filter
Applying this mapping to the transfer function of the low-pass filter for
the derivative results in the following,
In practice, one often treats the derivative term as a whole,
discretizing the derivative and the low-pass filter in one go by combining
their transfer functions and then applying forward Euler:
Other discretization methods
An alternative method is the bilinear transform (also known as the trapezoidal rule or Tustin's rule), it is of a higher order than forward and backward Euler, and has some nice properties such as the fact that stable poles in one domain map to stable poles in the other. Other techniques include pole-zero matching, matched step response, frequency response approximations, but these are outside of the scope of this article as they are not usually applied to PID controllers.
Overview
The following table gives an overview of all signals that make up the PID control law, as well as their discretizations. The third column is the most important one, because the discrete-time recurrence relations can easily be implemented in software.
Continuous-time | Discrete-time | ||
---|---|---|---|
Derivative on measurement
One disadvantage of the PID topology discussed above is that the derivative
component will become very large if the reference
The solution is really simple: instead of the derivative of the error,
the derivative of the measurement is used. The former is known as
“derivative on error”, the latter as “derivative on measurement”.
Both topologies are equivalent if the reference is constant, because
if
Figure 4 shows a block diagram of this new derivative on measurement topology, including the low-pass filter on the derivative.