You are on page 1of 34

DEPARTMENT OF BIOTECHNOLOGY ENGINEERING NASSERELDEEN AHMED Kabbashi nasreldin@iium.edu.my, Tel : Ext.

4524 Sem I, 2011-2012

A brief overview of basic concepts in Designing PID controller

PID use MATLAB


In this tutorial, we will consider the following unity feedback system: The transfer function of the PID controller looks like the following:

KI K Ds 2 K P s K I KP K Ds s s

where Kp is the proportional gain, Ki is the integral gain, and Kd is the derivative gain. The variable e is the tracking error or the difference between the desired reference value (r) and the actual output (y).
Dr. Nassereldeen A. Kabbashi

The three-term controller


Kp = Proportional gain KI = Integral gain Kd = Derivative gain The variable (e) represents the tracking error, the difference between the desired input value (R) and the actual output (Y). This error signal (e) will be sent to the PID controller, and the controller computes both the derivative and the integral of this error signal. The signal (u) just past the controller is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.

The controller takes this error signal and computes both its derivative and its integral. The signal which is sent to the actuator (u) is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the errorGenerally speaking, for an open-loop transfer function which has the canonical second-order form of

1 s 2 2 s 2

a large Kp will have the effect of reducing the rise time and will reduce (but never eliminate) the steady-state error. Integral control (Ki) will have the effect of eliminating the steady-state error, but it will make the transient response worse. If integral control is to be used, a small Ki should always be tried first. Derivative control will have the effect of increasing the stability of the system, reducing the overshoot, and improving the transient response. The effects on the closed-loop response of adding to the controller terms Kp, Ki and Kd are listed in table form below.

Dr. Nassereldeen A. Kabbashi

PID Controller
RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR

Kp

Decrease

Increase

Small Change Increase

Decrease

Ki

Decrease

Increase

Eliminate

Kd

Small Change

Decrease

Decrease

Small Change

Note that these correlations are not exactly accurate, because Kp, Ki, Kd are related to each other. Changing one of these variables can change the effect of the other two. For this reason, the table should only be used as a reference when you are determining the values for Ki, Kp and Kd by trial & error.
BTE 4415 Dr. Nassereldeen A. Kabbashi

Open-loop step response


Many PID controllers are designed by the trial & error selection of the variables Kp, Ki, and Kd. There are some rules of thumb that you can consult to determine good values to start from; see your controls book for some explanations of these recommendations. Suppose we have a second-order plant transfer function:

X ( s) 1 2 F ( s) s 10 20
Lets first view the open-loop step response. To model this system into Matlab, create a new m-file and add in the following code:
Dr. Nassereldeen A. Kabbashi

P- Controller

From the following TF

X ( s) 1 2 F ( s) s 10 20

The goal of this problem is to show you how each of Kp, Ki and Kd contributes to obtain Fast rise time, Minimum overshoot , No steady-state error Create a new m-file and add in the following code: num=1; den=[1 10 20]; step(num,den)
BTE 4415 Dr. Nassereldeen A. Kabbashi

Open-loop step response

Let's first view the open-loop step response. Create a new m-file and add in the following code: num=1; den=[1 10 20]; step(num,den) Running this m-file in the Matlab command window

Dr. Nassereldeen A. Kabbashi

BTE 4415

TF ANALYSIS

The gain of the plant transfer function is 1/20, so 0.05 is the final value of the output for a unit step input. This corresponds to a steady-state error of 0.95, quite large indeed. Furthermore, the rise time is about one second, and the settling time is about 1.5 seconds. Most likely, this response will not be adequate. Therefore, we need to add some control.
Dr. Nassereldeen A. Kabbashi

Proportional control

From the chart above we see that Kp will help us to reduce the steady-state error. Lets first add a proportional controller into the system, by changing your m-file to look like the following: num=1; den=[1 10 20]; Kp=10; [numCL,denCL]=cloop(Kp*num,den, -1); t=0:0.01:2; step(numCL, denCL,t)
Dr. Nassereldeen A. Kabbashi

Continue

The cloop command in Matlab is used to convert the open loop transfer function into a closed-loop one. Since the cloop command only accepts one transfer function, the plant and controller transfer functions have to be multiplied together before the loop is closed. It should also be noted that it is not a good idea to use proportional control to reduce the steady-state error, because you will never be able to eliminate the error completely. This fact will become evident below. If you rerun you m-file, you should get the following plot:

Dr. Nassereldeen A. Kabbashi

Continue

The rise time has been reduced The steady-state error is smaller, if we use a greater Kp, the rise time and steady-state error will become even smaller.
Dr. Nassereldeen A. Kabbashi

Continue
Change the Kp value in the m-file: Kp=500; Rerun the m-file and you should get the following plot:

Dr. Nassereldeen A. Kabbashi

Continue

This time we see that the rise time is now about 0.1 second and the steady-state error is much smaller. But the overshoot has gotten very large. From this example we see a large proportional gain will reduce the steady-state error but at the same time, worsen the transient response. If we want a small overshoot and a small steady-state error, a proportional gain alone is not enough.

Dr. Nassereldeen A. Kabbashi

Continue

We see that the proportional controller (Kp) reduces the rise time, increases the overshoot, and reduces the steady-state error. The closed-loop transfer function of the above system with a proportional controller is:

X(s) Kp 2 F(s) s 10s (20 K p )


BTE 4415 Dr. Nassereldeen A. Kabbashi

Continue

Let the proportional gain (Kp) equals 300 and change the m-file to the following: Kp=300; num=[Kp]; den=[1 10 20+Kp]; t=0:0.01:2; step(num,den,t) Running this m-file in the Matlab command window

Dr. Nassereldeen A. Kabbashi

BTE 4415

NB

Note: The Matlab function called cloop can be used to obtain a closed-loop transfer function directly from the open-loop transfer function (instead of obtaining closed-loop transfer function by hand). The following m-file uses the cloop command that should give you the identical plot as the one shown above. num=1; den=[1 10 20]; Kp=300; [numCL,denCL]=cloop(Kp*num,den); t=0:0.01:2; step(numCL, denCL,t)
Dr. Nassereldeen A. Kabbashi BTE 4415

Continue

The above plot shows that the proportional controller reduced both the rise time and the steadystate error, increased the overshoot, and decreased the settling time by small amount

Dr. Nassereldeen A. Kabbashi

BTE 4415

PD control

The rise time is now probably satisfactory (rise time is about 0.1 second). Now lets add a derivative controller to the system to see if the overshoot can be reduced. Add another variable, Kd, to the m-file, set it equal to 10 and rerun the m-file: Kp=500; Kd=10; numc=[Kd Kp]; [numCL, denCL]=cloop(conv(num,numc),den); step(numCL, denCL,t)

Dr. Nassereldeen A. Kabbashi

Continue

The overshoot is much less then before. It is now only twenty percent instead of almost forty-five percent. We can now try to improve that even more. Try increasing Kd to 100, you will see the overshoot eliminated completely. We now have a system with a fast rise time and no overshoot. Unfortunately, there is still about a 5 percent steady-state error. It would seem that a PD controller is not satisfactory for this system. Lets try a PI controller instead.

Dr. Nassereldeen A. Kabbashi

Proportional-Derivative control
From above, we see that the derivative controller (Kd) reduces both the overshoot and the settling time. The closed-loop transfer function of the given system with a PD controller is

KDs K p X ( s) 2 F ( s) s (10 K D ) s (20 K p )


BTE 4415 Dr. Nassereldeen A. Kabbashi

Let Kp equals to 300 as before and let Kd equals 10. Enter the following commands into an m-file and run it in the Matlab command window. Kp=300; Kd=10; num=[Kd Kp]; den=[1 10+Kd 20+Kp]; t=0:0.01:2; step(num,den,t) : This plot shows that the derivative controller reduced both the overshoot and the settling time, and had small effect on the rise time and the steady-state error.
Dr. Nassereldeen A. Kabbashi BTE 4415

PI control

proportional control will reduce the steady-state error, but at the cost of a larger overshoot. Furthermore, proportional gain will never completely eliminate the steady-state error. For that we need to try integral control. Lets implement a PI controller and start with a small Ki. Go back to the m-file and change it so it looks like the following (note the t input is removed from the step command so more of the response can be seen):

Dr. Nassereldeen A. Kabbashi

Continue

Kp=500; Ki=1; Kd=0; numc=[Kd Kp Ki]; denc=[1 0]; [numCL, denCL]=cloop(conv(num,numc),conv(den,denc)); step(numCL, denCL)

Dr. Nassereldeen A. Kabbashi

Continue

The Ki controller really slows down the response. The settling time becomes more than 500 seconds. To reduce the settling time, we can increase Ki, but by doing this, the transient response will get worse (e.g. large overshoot). Try Ki=10, by changing the Ki variable. The plot can be see better if an axis command is added after the step response.

Dr. Nassereldeen A. Kabbashi

Continue

The m-file now look like the following: Kp=500; Ki=10; Kd=0; numc=[Kd Kp Ki]; denc=[1 0]; [numCL, denCL]=cloop(conv(num,numc),conv(den,denc)); step(numCL, denCL) axis([0 100 0 1.5])

Dr. Nassereldeen A. Kabbashi

Analysis

Now we have a large overshoot again, while the settling time is still long. To reduce both settling time and overshoot, a PI controller by itself is not enough.

Dr. Nassereldeen A. Kabbashi

Proportional-Integral control
We see that an integral controller (Ki) decreases the rise time, increases both the overshoot and the settling time, and eliminates the steady-state error. For the given system, the closed-loop transfer function with a PI control is:

K ps K I X(s) 3 2 F(s) s 10s (20 K p )s K I


BTE 4415 Dr. Nassereldeen A. Kabbashi

Let's reduce the Kp to 30, and let Ki equals to 70. Create an new m-file and enter the following commands. Kp=30; Ki=70; num=[Kp Ki]; den=[1 10 20+Kp Ki]; t=0:0.01:2; step(num,den,t) Run this m-file in the Matlab command window We have reduced the proportional gain (Kp) because the integral controller also reduces the rise time and increases the overshoot as the proportional controller does (double effect). The above response shows that the integral controller eliminated the steadystate error
Dr. Nassereldeen A. Kabbashi BTE 4415

PID control

From the two controllers above, we see that if we want a fast response, small overshoot, and no steady-state error, neither a PI nor a PD controller will suffice. Lets implement both controllers and design a PID controller to see if combining the two controllers will yield the desired response. Recalling that our PD controller gave us a pretty good response, except for a little steady-state error. Lets start from there, and add a small Ki (1).

Dr. Nassereldeen A. Kabbashi

Continue

Change your m-file to the following to implement the PID controller and plot the closed-loop response: KP=500; KI=1; KD=100; numc=[KD KP KI]; denc=[1 0]; [numCL, denCL]=cloop(conv(num,numc),conv(den,denc)); step(numCL, denCL) The settling time is still very long. Increase Ki to 100.
Dr. Nassereldeen A. Kabbashi

Continue

The settling time is much shorter, but still not small enough. Increase Ki to 500 and change the step command to step(numCL, denCL,t) Now the settling time reduces to only 1.5 seconds. This is probably an acceptable response for this system. To design a PID controller, the general rule is to add proportional control to get the desired rise time, add derivative control to get the desired overshoot, and then add integral control (if needed) to eliminate the steady-state error. You may have to go back and readjust all three variables to fine-tune the response.

Dr. Nassereldeen A. Kabbashi

Proportional-Integral-Derivative control let's take a look at a PID controller. The closed-loop transfer function of the given system with a PID 2 controller is: X(s) K Ds K p s K I 3 2 F(s) s (10 K D )s (20 K p )s K I
After several trial and error runs, the gains Kp=350, Ki=300, and Kd=50 provided the desired response. To confirm, enter the following commands to an m-file and run it in the command window.

BTE 4415

Dr. Nassereldeen A. Kabbashi

Continue

You should get the following step response. Kp=350; Ki=300; Kd=50; num=[Kd Kp Ki]; den=[1 10+Kd 20+Kp Ki]; t=0:0.01:2; step(num,den,t)

Dr. Nassereldeen A. Kabbashi

BTE 4415

You might also like