Lecture 17 - PID controller (notes)
Lecture 17 - PID controller (notes)
Even if the system is not unstable and eventually settle down to the steady-state
value, the system output may exhibition large overshoot transient behaviour, similar
to what you saw with the Bulb Box system when it is driven by a step signal. Since
such a system is prone to oscillation, it may also take a long timer before it reaches
the final steady-state condition.
Finally, using P-only control may not give us the tolerance to perturbation required.
Note that the term 1/Δ𝑡 is often “absorbed” into the derivative gain Kd.
What does the derivative term do to the behaviour of the system? The derivative
term acts as “brake” to the system. As the error is reducing (rate of error is
negative), it reduces the drive to the plant (i.e. braking), and therefore prevents
overshoot.
The derivative term can also make the system more tolerant to external
disturbances.
Another common improvement to the P-only control is the proportional-integral (PI)
control. Here we add another term that is dependent on the integral of the error over
time. The time domain description of the controller is:
𝑤 𝑡 = 𝐾! 𝑒 𝑡 + 𝐾$ ; 𝑒 𝜏 𝑑𝜏
Again in practical electronics and programming, we implement the integral term as a
summation. Integration in calculus is the same as accumulation of area under the
curve. Therefore in discrete domain, we simply sum the error from t = 0:
(
integral term at time n = 𝐾$ Δ𝑡 ? 𝑒[𝑛 − 𝑘]
%&'
As before, Δ𝑡 is often “absorbed” into the Ki term.
Remember that the Laplace transform of an integral is 1/s. Therefore the s-domain
representation of the PI controller (i.e. the transfer function) is: 1
𝐺# 𝑠 = 𝐾! + 𝐾$
𝑠
PI controller accumulates error to produce a constant output u(t) that is sufficient to
drive the plant to give the desired output value y(t). When that happens, e(t) = 0, and
yet the output y(t) = r(t) is maintained. It can be seen that this cannot be achieved with
P-only controller. For example, in order to drive a DC motor at a certain speed, we
need the input PWM duty cycle to be w(t) = pwm_value. With proportional gain we
need an error e(t) = pwm_value/Kp. Unless Kp is infinite, e(t) is NOT 0.
However, with PI controller, the integral term will accumulate to pwm_value and now
e(t) = 0 and w(t) will stay constant.
A PI controller will work with the P term gain Kp = 0 (i.e. I-only control), but its response
to a step input would be slower. The integral action will take time to reach the desired
value. However, PD controller WILL NOT work with D-only!
Finally, we can combine all three terms (P, I and D) together to make a PID
controller. This has all the benefits of proportional control, integral control and
derivative control. Not that PID control is a generalised version of all the other form
with the appropriate gains set to some constant or 0.
https://www.youtube.com/watch?v=XfAt6hNV8XM
PID control structure is therefore very general. Designing a controller for a given
plant or process requires us to determine the correct value for Kp, Ki and Kd. This
process is known as “tuning”.
Before we consider how to tune a PID controller, you should know the effect of each
of increasing Kp, Ki and Kd on the feedback system behaviour in terms of overshoot,
settling time and steady-state error (i.e. e(t) value after the system settle to final
condition).
Note that the Z-N tuning method may not provide you with the optimum
performance or best disturbance tolerance. It however does provide a guide on
how to set the different gain values for a reasonably good control system.
Also, in this formulation, the gain terms are all expressed in terms of Ku (Kp is
factorised to outside the brackets), and the oscillation period Tu (Ti and Td are
specified in terms of Tu).
A good alternative to the Z-N tuning method is one described here. This does not
involved measuring the oscillation period, or just setting gain values based on
measured parameters.
Instead it uses a trial-and-error approach: in turn pushing Kp, then Kd and Ki to the
limit until the system becomes unstable, and dial each back to half way or smaller.
Finally, let me relate what you have learned in feedback control to the team project.
The task at hand is to balance the Segway so that it can stand upright without falling
over. The system (the plant) is inherently unstable (i.e. will NOT balance on its own).
Feedback control is necessary for the Segway to self balance.
The variable under control is NOT speed of the Segway, but its pitch angle. To do
that, we will use a PID controller.
The pitch angle is measured and is compared to the set-point, which is zero if the
Segway is upright. This error is multiplied by Kp and used as part of the PWM value
to drive the motors in the direction that corrects the error.
The derivative control is NOT achieved by differentiating the error e(t). Instead we
will use the gyroscope reading for y-axis, which measures the rate of change of the
pitch angle (i.e. 𝑝).
̇ We multiple 𝑝̇ with Kd to get the derivative term. Finally we
integrate the value p and multiply this with Ki to get the integral term. Now we add
these together to provide the drive to the motors. Remember that we need to limit
this value to +/- 100 (duty cycle cannot exceed 100, and +/- indicates direction of
motor).
To move the Segway forward or backward, all you need is to change the set-point
(target pitch angle). This is actually how it works on a real Segway.
Finally turning can be achieved by changing the ratio of the PWM values driving the
left and the right motor. Having the two wheels at different speed will make the
Segway turn.