Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CONTROL SYSTEMS
(EEE 325)
ENGR. NASEER ALI BAJWA
ii
7.2 Design Problem: Tracked Vehicle Turning Control 86
iii
Lab Session 1: MATLAB Review for Control Systems
LAB SESSION 1:
Objectives:
This lab presents a brief revision of MATLAB environment. It also provides
tutorial on variables, vectors, matrices, basic linear algebra, plotting and flow
control in MATLAB.
Deliverables:
A complete lab report including the following:
Introduction:
In this exercise you will be introduce to the concept of mathematical
programming using MATLAB. We shall study how to define variables, handle
matrices and see how we can plot results and write simple MATLAB codes to
perform our desired task.
1 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
variable_name = value
variable_name = expression
There are, however, some rules that must be followed, while naming the
variables, such as;
Note that MATLAB is case sensitive, i.e. one & OnE are different variables.
1.1.2 VECTORS
A row vector in MATLAB can be created by an explicit list, starting with a left
square bracket, entering the values separated by spaces (or commas) and
closing the vector with a right square bracket. A column vector can be created
the same way, and the rows are separated by semicolons.
2 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
ARRAY ADDRESSING:
A vector element is addressed in MATLAB with an integer index enclosed in
parentheses like;
>> x(3)
ans =
1.5708
Where start is the starting index, increment is the amount to add to each
successive index, and end is the ending index. A shortened format (start:end)
may be used if increment is 1. Verify the following code and outcomes.
>> x(1:4)
ans =
1.0000 2.5000 4.0000 5.5000
>>x(2:2:8)
ans =
2.5000 5.5000 8.5000 11.5000
Note that MATLAB index starts at 1 and the default increment in an array index
is also 1.
3 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
1.1.3 MATRICES
A Matrix is a two-dimensional array, having multiple rows and multiple
columns. Similar to vector arrays;
>> f = [ 1 2 3; 4 5 6]
f =
1 2 3
4 5 6
>> h = [ 2 4 6
1 3 5]
h =
2 4 6
1 3 5
MATRIX ADDRESSING:
Any element in a matrix can be accessed by
Colon may be used in place of a row or column reference to select the entire
row or column. For example for the abovementioned matrix f;
>> f(:,1)
ans =
1
4
4 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
>> f(1,:)
ans =
1 2 3
size (A) for an m x n matrix A, returns the row vector containing the
number of rows and columns in matrix.
5 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
>> z = 1 + 0.5j;
>> plot (z, ‘.’)
Multiple curves can be plotted on the same graph by using multiple arguments
in a plot command.
6 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
( )
This is the celebrated example Wallis used when he first represented Newton's
method to the French Academy. To enter this polynomial into MATLAB, use
>> p = [1 0 -2 -5];
Now use roots function to find the roots of this polynomial and note them
down,
>> r = roots(p);
7 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
The function poly returns the polynomial coefficients. Try it and record the
output.
You may have noticed that poly and roots are inverse functions.
The roots of this polynomial, computed with roots, are the characteristic roots,
or eigenvalues, of the matrix A. You may also use eig to compute the
eigenvalues of a matrix directly.
8 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
Explore the polyder() function using help command and use its all three
variants.
( )
( )
9 | Page
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
Given three input arguments (r, p, and k), residue converts back to
polynomial form, try this out.
>> syms t s
Next you define the function f(t). The actual command to calculate the
transform is
>> F = laplace(f,t,s)
( )
>> syms t s
>> f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
>> F=laplace(f,t,s)
F =
To make the expression more readable one can use the commands simplify
and pretty.
>> simplify(F)
ans =
(s-5)/s/(s+2)^2
>> pretty(ans)
s - 5
----------
s (s + 2)2
( )
( )
Alternatively, one can write the function f(t) directly as part of the Laplace
command:
>>F2=laplace(-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t))
syms s;
ans =
2 ( ) g = 1/sqrt(s);
√ pi^(1/2)/t^(1/2)
laplace(g)
syms t a x; ans =
( )
3 f = exp(-a*t); 1/(a + x)
laplace(f,x)
12*s^2*laplace(y(t)
G =
4 ( ) , t, s) - 12*s*y(0)
laplace(12*diff(sym('y(t)'),2))
- 12*D(y)(0)
11 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
Note that in the last example, the function y(t) is defined as symbol with the
command sym. The number 2 in diff function means we wish to take the
second derivative of the function y(t).
( )
( )
>> syms t s
>> F=(s-5)/(s*(s+2)^2);
>> ilaplace(F)
ans =
-5/4+(7/2*t+5/4)*exp(-2*t)
>> pretty(ans)
- 5/4 + 7/2 t exp(-2 t) + 5/4 exp(-2 t)
Which corresponds to
( )
>> ilaplace((s-5)/(s*(s+2)^2))
( )
( )
( )
>> F=10*(s+2)/(s*(s^2+4*s+5));
>> ilaplace(F)
ans =
-4*exp(-2*t)*cos(t)+2*exp(-2*t)*sin(t)+4
12 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
syms a t;
ans =
2 ( ) g = 1/(t-a)^2;
( ) pi^(1/2)/t^(1/2)
ilaplace(g)
syms x u;
ans =
( ) syms a real;
3 sinh(a*x)/a
f = 1/(u^2-a^2);
simplify(ilaplace(f,x))
ans =
ilaplace(1/s-
4 ( ) 1/exp(5*t) -
2/(s+4)+1/(s+5))
2/exp(4*t) + 1
1.5.1 SCRIPTS:
Script files do not accept input arguments or return output arguments. They
operate on data in the base workspace, the same workspace that command
window uses. MATLAB provides a full programming language that enables you
to write a series of MATLAB statements into a file and then execute them with a
single command. You write your program in an ordinary text file, giving the file
a name, say, ‘filename.m’. The term you use for ‘filename’ becomes the new
command that MATLAB associates with the program. The file extension of .m
makes this a MATLAB M-file. When you invoke a script, MATLAB simply executes
the commands found in the file.
13 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
Scripts can operate on existing data in the workspace, or they can create new
data on which to operate. Although scripts do not return output arguments,
any variables that they create remain in the workspace, to be used in
subsequent computations. In addition, scripts can produce graphical output
using functions like plot.
1.5.2 FUNCTIONS:
Functions are M-files that can accept input arguments and return output
arguments. The names of the function file and of the function name should be
the same. Functions operate on variables within their own workspace, separate
from the workspace you access at the MATLAB command prompt. An example is
provided below:
The first definition line of a function M-file starts with the keyword function. It
gives the function name, number and order of input/output arguments. In the
above example, there is one input argument, n, and one output argument, f.
The next several lines, up to the first blank or executable line, are comment
lines that provide the help text. These lines are printed when you type help
fact. The first line of the help text is the H1 line, which MATLAB displays when
you use the lookfor command or request help on a directory. The rest of the
file is the executable MATLAB code defining the function.
The variable n & f introduced in the body of the function as well as the
variables on the first line are all local to the function; they are separate from
any other variables in the MATLAB workspace. This example illustrates one
aspect of MATLAB functions that is not ordinarily found in other programming
languages — variable number of arguments. Many M-files work this way. If no
output argument is supplied, the result is stored in ans. If the second input
argument is not supplied, the function computes a default value.
14 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
IF-ELSE-ELSEIF
if A == B
This is valid MATLAB code, and does what you expect when A and B are scalars.
But when A and B are matrices, A == B does not test whether they are equal, it
tests where they are equal; the result is another matrix of 0's and 1's showing
element-by-element equality. In fact, if A and B are not the same size, then A ==
B is an error. Write this code and record output
>>A = magic(4);
>>B = A;
>>B(1,1) = 0;
>>A == B
The proper way to check for equality between two variables is to use the
isequal() function:
if isequal(A, B)
>>isequal(A, B)
15 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
ans =
0
Here is another example to emphasize this point. If A and B are scalars, the
following program will never reach the "unexpected situation". But for most
pairs of matrices, including our magic squares with interchanged columns,
none of the matrix conditions A > B, A < B, or A == B is true for all elements
and so the else clause is executed:
if A > B
'greater'
elseif A < B
'less'
elseif A == B
'equal'
else
error('Unexpected situation')
end
n=5
switch rem(n,2) % to find remainder of any number ‘n’
case 0
disp(‘Even Number’) % if remainder is zero
case 1
disp(‘Odd Number’) % if remainder is one
end
Unlike the C language switch statement, MATLAB switch does not fall through.
That is, if the first case statement is true, the other case statements do not
execute. So, break statements are not required.
for n = 1:4
16 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
The while loop repeats a group of statements indefinite number of times under
control of a logical condition. So a while loop executes at least once before it
checks the condition to stop the execution of statements. A matching end must
complement the statement. Syntax is given below.
while <condition>
<statements>;
end
17 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
EXERCISE 1:
Explore magic() command of MATLAB. Try A = magic(5), record your output
and explain.
EXERCISE 2:
Consider two polynomials ( ) and ( ) . Using MATLAB,
find
p(s)*q(s)
Roots of p(s) and q(s)
p(-1) and q(6)
Write code and record output.
EXERCISE 3:
Use MATLAB to find partial fraction of the following
( )
( )
( )
( ) ( )
EXERCISE 4:
Use MATLAB to generate the first 100 terms in the sequence a(n) define
recursively by
( ) ( ) ( ( ))
EXERCISE 5:
Use for or while loop to convert degrees Fahrenheit to degrees Celsius using
the following equation
18 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 1: MATLAB Review for Control Systems
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
19 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
Lab Session 2:
MATHEMATICAL MODELIN G OF
PHYSICAL SYSTEMS
PREREQUISITES:
The students are expected to be familiar with MATLAB environment in addition
to the understanding of physical laws governing electrical, mechanical and
translational systems.
OBJECTIVES:
The objective of this lab is to be able to develop mathematical models of
physical systems such as electrical circuits or mass-spring translational
systems.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
“All models are wrong but some are useful”
(George Box)
Mathematical Modeling means describing a physical system using
mathematical concepts and language. It is the first step in studying the
behavior of the system at hand. These mathematical models help the designers
in not only analyzing an existing system but also designing new systems with
more desirable behavior as per the specific needs of an application.
Unfortunately we can never make a completely precise model of a physical
system. There are always phenomena which we will not be able to model. Thus,
there will always be model errors or model uncertainties. But even if a model
21 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
describes just a part of the reality it can be very useful for analysis and design
— if it describes the dominating dynamic properties of the system.
the acceleration a of a body is parallel and directly proportional to the net force
F acting on it and inversely proportional to the mass M of the body. Let we
apply a force Fa(t) on the mass M and displace it from its mean position, say
22 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
x0, to a new position, say x1. At this point there will be other forces acting on
the mass M besides our applied force.
One of these three forces is Friction Force, Ff(t). For the simplicity we assume
here that the wall friction b is a viscous damper, that is, the friction force is
linearly proportional to the velocity of the mass. In reality, however, this friction
force may behave as a coulomb damper, also known as dry friction, which is a
nonlinear function of the mass velocity. For a well-lubricated, sliding surface,
the viscous friction is an appropriate approximation. Hence for friction force,
Ff(t), we can write that
( ) ( ) (2.1)
This friction force will obviously be in the reverse direction of applied force.
Another force acting on the mass is the spring force which is also in the
opposite direction to the applied force. According to Hook’s Law the extension
of a spring is directly proportional to the applied load as long as the load does
not exceed spring’s elastic limits. Mathematically Hook’s law can be stated as
( ) ( ) (2.2)
Here Fs(t) is spring force, k is the spring constant and x is the displacement as
a result of applied force.
∑ (2.3)
from figure 2.1(b) we note that there are a total of three forces acting on the
mass M. So,
∑ (2.4)
Putting (1), (2), and (4) in (3) and rearranging the term, we get
( ) ( ) (2.5)
( ) ( )
23 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
( )
( )
( )
Where R(s) is and E(s) are Laplace Transforms of Response (output) and
Excitation (input) respectively.
For the system given above we take applied force Fa to be input to the system
and let displacement x(t) be out output. So after taking Laplace transform we
get the following expression assuming zero initial conditions.
( ) ( ) ( ) ( ) (2.6)
( ) ( ) ( ) (2.7)
( )
Hence the transfer function will be,
( )
( ) (2.8)
( )
Transfer function:
-------------------
200 s^2 + 25 s + 10
If we have a transfer function object sys and we want to find the numerator
and denominator polynomials we can use the following command
Please note that in transfer function model you have direct control over
coefficients or weights of each and every term involved in the system. By
changing these parameters we can observe the change in the system response.
You may remember from your DSP course that these weights in a filter transfer
function are of utmost importance and having direct access to these
coefficients means that you can easily change the gain response of the filter as
per you requirement.
>> p = pole(sys)
>> z = zero(sys)
We can also use pzmap() function to find both poles and zeros in one go as
25 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
We can also store the complete system in pole-zero-gain form in a single object.
Explore the following command
This command will create and store a mathematical model by using given
locations of zeros (stored in z vector), poles (stored in p vector) and a scalar
value k.
We can infer from the above command that this model gives direct access to
the poles’ and zeros’ locations and designer can easily change these locations
to study the response and stability of a system.
However there are commands that can transform one model representation to
the other. Explore the following commands
[num,den] = zp2tf(z,p,k)
(2.9)
∫
26 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
If we are interested in observing the capacitor voltage then our output will be
(2.10)
∫
Taking Laplace transform of (9) and (10) will yield,
(2.11)
( ) ( ) ( ) ( )
(2.12)
( ) ( )
Now dividing (12) with (11) will result in the transfer function of this RLC
Circuit
( ) (2.13)
( )
You can now describe this system in MATLAB either by tf() command or zpk()
command.
27 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
( ) (2.14)
( ) ( )( )
Kindly note that R1C1s in the denominator of the transfer function represents
the interaction of two simple RC circuits. If this term were not present in the
transfer function then this system could be modeled as cascade of two RC
circuits but in this case it’s not possible. The reason for this is that, when we
derive the transfer function for an isolated circuit, we implicitly assume that
the output is unloaded. In other words the load impedance is assumed to be
infinite, which means that no power is being withdrawn at the output. When
the second circuit is connected to the output of the first, however, a certain
amount of power is withdrawn, and thus the assumption of no-loading is
violated. However, if the input impedance of the second system is infinite (or
sufficiently large), the output of the first system is not affected by connecting it
to the second system. Then the overall transfer function of the whole system
can be thought of as the product of the two transfer functions corresponding to
the individual systems. Alternatively, we can introduce an isolating amplifier
for impedance matching between the two cascaded stages.
Consider simple Op-Amp circuits shown above in Figure 2.4. The configuration
in Figure 2.4(a) is known as an integrator because it integrates the given signal
over time and the circuit in 2.4(b) is a diffentiator. These two circuits along with
the most basic configuration of Op-Amp as an amplifier constitute majority of
the electronic controllers commonly referred to as PID controllers (PID stands
for Proportional plus Integral plus Differential). PID controllers will be studied
in depth in the forthcoming labs. For now, let’s find transfer function for these
simple controllers.
(2.15)
( )
( ) (2.16)
29 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
Since , so
( ) (2.17)
Taking Laplace transform and rearranging the terms gives the transfer
function.
(2.18)
(2.19)
(2.20)
30 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
EXERCISE 1:
Develop mathematical model of the following lead-lag network. Represent this
model in both transfer function form and pole-zero-gain form.
EXERCISE 2:
The output of the above network is inverted. This is normally rectified by
cascading an inverting amplifier at the output of the lead-lag network as shown
below. Find the overall transfer function of two cascaded system.
31 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 2: MATHEMATICAL MODELING OF PHYSICAL SYSTEMS
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
32 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
Lab Session 3:
OBJECTIVES:
This lab starts with block diagram reduction techniques, and their MATLAB
implementation. The simulation of a given system against simple inputs is then
presented. Finally, an introduction to Simulink is given to familiarize the
students with modeling and simulation in graphical environment.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
In this exercise our prime objective is to simulate Linear Time-Invariant
Systems. We will start by understanding the interconnection of various system
components and methods to reduce a rather complex-looking system to a
simple transfer function. These techniques facilitate the control engineers to
analyze the whole system as a single unit and study its overall behavior.
33 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
( )
And G2(s) is
( )
( )
If we know the transfer functions of the subsystems, G1(s) and G2(s), then we
can find the transfer function of T(s) by using the following MATLAB command.
It will consume both transfer functions and the summing junction and give a
single block between U(s) and Y(s) equivalent to the consumed components
( ) ( )
( )
( ) ( ) ( )
35 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
feedback style.
Now assume that G2(s) = 1, that means we have connected output back to the
input directly without any transfer function involved. It would result in a
special feedback loop, called unity feedback, as shown in figure 3.4. Total
transfer function, T(s), in this case would then be,
( ) ( )
( )
( ) ( )
36 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
move summing junction and/or pickoff points back or forth to save the signals.
Figure 3.5 illustrates the rules governing such movements.
37 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
Use the block diagram algebra given in figure 3.5 to reduce the following block
diagram to a single block.
( )
Now use MATLAB to find the equivalent transfer function, , given that
( )
Then we can find the impulse response of such a system by using impulse
command
>> impulse(LTIsys)
There exists another variant of impulse command that allows us to observe the
impulse response over a specified duration of time. The variant is,
>> impulse(LTIsys,t)
This command sets the simulation horizon explicitly. We can specify either a
final time t = Tfinal (in seconds), or a vector of evenly spaced time samples
of the form
>> t = 0 : dt : Tfinal
For discrete systems, the spacing dt should match the sample period. For
continuous systems, dt becomes the sample time of the discretized simulation
model, so in this later case the choice of dt should be small enough to capture
transient phenomena.
>> impulse(sys1,sys2,...,sysN)
>> impulse(sys1,sys2,...,sysN,t)
As with plot, we can specify a particular color, line style, and/or marker for
each system, for example,
>> impulse(sys1,'y:',sys2,'g--')
39 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
Furthermore, the overall system cannot proceed until the component's output
settles down to some vicinity of its final state, consequently delaying the overall
system response. Normally, knowing the step response of a dynamical system
gives information on the stability of such a system, and on its ability to reach
one stationary state when starting from another.
In MATLAB we use the following commands to find the step response of an LTI
system.
>> step(LTIsys)
This command plots the step response of an arbitrary LTI model. This model
can be continuous or discrete, and SISO or MIMO. The step response of multi-
input systems is the collection of step responses for each input channel. The
duration of simulation is determined automatically, based on the system poles
and zeros.
>> step(sys,t)
Similar to impulse command, step also has a variant to set the simulation
horizon explicitly. We can specify either a final time t = Tfinal (in seconds),
or a vector of evenly spaced time samples of the form t = 0 : dt : Tfinal.
To plot the step response of several LTI models sys1,..., sysN on a single
figure, use
>> step(sys1,sys2,...,sysN)
>> step(sys1,sys2,...,sysN,t)
All of the systems plotted on a single plot must have the same number of
inputs and outputs. We can, however, plot a mix of continuous- and discrete-
time systems on a single plot. This syntax is useful to compare the step
responses of multiple systems.
We can also specify a distinctive color, line style, marker, or all three for each
system. For example,
>> step(sys1,'y:',sys2,'g--')
plots the step response of sys1 with a dotted yellow line and the step response
of sys2 with a green dashed line.
40 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
return the output response y and the time vector t used for simulation. No plot
generates on the screen.
>> lsim(LTIsys,u,t)
It produces a plot of the time response of the LTI model LTIsys to the input
vector u over time t. The vector t specifies the time for the simulation and
consists of regularly spaced time samples.
>> t = 0:dt:Tfinal
If the system is multi-input, we can make u as a matrix. In this case the matrix
u must have as many rows as time samples (length(t)) and as many columns
as system inputs. Each row u(i,:) specifies the input value(s) at the time
sample t(i).
>> lsim(sys1,sys2,...,sysN,u,t)
simulates the responses of several LTI models to the same input history t, u
and plots these responses on a single figure.
41 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
it returns the output response y and the time vector t used for simulation. No
plot is drawn on the screen.
As lsim command requires a user defined input vector u, let’s now see a couple
of techniques to construct this vector.
( ) ( ) ( )
This will plot the system response to the given input over the given interval.
To construct periodic signals, MATLAB has a very handy command gensig. Its
syntax is,
This command generates a scalar signal u of class type and with period tau (in
seconds). The following types of signals are available.
gensig returns a vector t of time samples and the vector u of signal values at
these samples. All generated signals have unit amplitude.
The abovementioned command also specifies the time duration Tf of the signal
and the spacing Ts between the time samples t.
Now that we have learnt how to apply various inputs to a given system, it’s
time to apply these commands to the systems developed in the previous lab.
42 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
1. Create a new block diagram by clicking File -> New -> Model
2. Rearrange the differential equation representing physical system in terms
of the highest derivative present in the equation. Make sure the highest
derivative has unit coefficient. For example to model the mass-spring
system described by equation (5) in the previous lab, we will rearrange
the equation as
( ) ( )
( ( ) ( ))
3. Identify the system components in your design. Find them from
appropriate library in Simulink Library Browser. Drag and Drop desired
components to the model file. For this mass-spring system we recognize
that;
a. Left-hand side term is equal to summation of three terms (two of
which are negative), so we need a summing component. Find it
under “Commonly Used Blocks” Library.
b. Two of the summing terms have weights i.e. they are multiplied by
some scalar coefficients. So we may need two scalar gain
components. We can find them under the same library as Gain
Components.
43 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
5. Set the design parameters. For this case double click step signal to set
an amplitude of 3 and step time equal to zero, set the coefficient values
as
M = 200 b = 25 k = 10
6. To run the simulation, simple click the run icon or selecting, from the
menu bar, Simulation -> Start. Double right click on the scope to observe
the output
44 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
( ) ( )
( )
Compare this to rearranged equation of mass-spring system given below
( ) ( )
( )
We find that
Calculate the values of , , and K and see if the simulation results are
correct.
Check out the following link to understand the relationship of these system
parameters on system response.
http://math.mit.edu/daimp/DampingRatio.html
45 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
EXERCISE 1:
( )
( )
(c) Explain why the results in (a) and (b) are same?
EXERCISE 2:
Design and simulate the RLC circuit given in last lab in MATLAB and Simulink
with the following input
( ) ( )
EXERCISE 3:
A system has a transfer function
( )
( )
Find the response of this system if the input is a ramp function with slop equal
to 4.
46 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 3: SIMULATION OF LTI SYSTEMS
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
47 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
Lab Session 4:
PERFORMANCE PARAMETERS OF
A CONTROL SYSTEM
PRE REQUISITES:
The students are expected to have firm understanding of block diagram
reduction techniques. As for MATLAB, they should be able to simulate any given
system against any input signal.
OBJECTIVES:
The objective of this exercise is to study the performance characteristics of first
and second-order systems using MATLAB.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
Primary concerns in control system design are performance and stability. In
order to design and analyze control systems, we must first establish adequate
performance specifications. Performance specifications can be presented in the
time domain or the frequency domain. Time-domain specifications generally
take the form of settling time, percent overshoot, rise time, and steady-state
error. Stability and frequency-domain specifications are addressed in coming
labs.
49 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
( )
( )
The standard performance measures are usually defined in terms of the step
response and the impulse response. The most common step response
performance measures are percent overshoot (P.O), rise time (tr), peak time (tp),
settling time (ts) and steady-state error (ess) as shown in figure 4.1.
50 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
4.1.4 OVERSHOOT
Overshoot is the maximum peak value of the response curve measured from
the desired response of the system. It is calculated as
Where Mp is the highest peak magnitude of output and fv is the final value of
the output.
In MATLAB, we use stepinfo command to get all the step response parameters.
>> stepinfo(sys)
51 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
>> stepinfo(sys)
ans =
RiseTime: 4.2568
SettlingTime: 35.3593
SettlingMin: 0.0438
SettlingMax: 0.0675
Overshoot: 35.0913
Undershoot: 0
Peak: 0.0675
PeakTime: 10.4917
The substation at the right of figure 4.2 performs the task of taking the power
provided by an electric utility power plant and converting it into a form of
power that the electric rail car can use to operate its traction motors. The two
terminals of this substation are connected via a trolley wire and the two rails
that the train runs on. The electric train has a spring-loaded arm called a
pantograph on its roof that touches the trolley wire, allowing electrical current
to flow into a speed control system housed under the train. This speed control
52 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
system performs the task of varying the flow of electrical current to the traction
motors, enabling the car to move, before it eventually exits the motor through
its wheels, then back to the substation where it originated, thus completing an
electrical circuit.
The speed control system of an electric train is shown in figure 4.3. Our goal in
this problem is to find the closed-loop transfer function and investigate the
response of to a commanded . The first step in this direction would be to
apply block diagram reduction techniques learnt in previous labs to compute
the closed-loop transfer function . We observe that closed-loop
characteristic equation is second-order with and . Since the
53 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
RiseTime: 0.0202
SettlingTime: 6.2294
SettlingMin: 0.0728
SettlingMax: 1.9624
Overshoot: 96.2920
Undershoot: 0
Peak: 1.9624
PeakTime: 0.0605
54 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
( )
We will later show that this G1(s) is a proportional plus integral (PI) controller.
We can simulate the closed-loop system to a ramp input using the lsim
command. The controller gains , and the system gain can be
represented symbolically in the script so that various values can be selected
and simulated.
55 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
56 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
EXERCISE 1:
Apply block diagram reduction techniques on model below to show that its
complete transfer function is
( )
( )
EXERCISE 2:
An electrical RC-circuit is the simplest example of a first order system. It
comprises of a resistor and capacitor connected in series to a voltage supply as
shown below. If and and we apply a DC voltage source of
8V, verify that capacitor’s charging curve follows the following proportions.
( )
( )
( )
( )
( )
57 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
EXERCISE 3:
To study the effects of damping ratio on the performance measures, consider
the following second-order single-loop unity feedback system.
Find the step response of the system for values of ωn = 1 and ζ = 0.1, 0.4, 0.7,
1.0 and 2.0.
Plot all the results in the same figure window and fill the following table.
0.1
0.4
0.7
1.0
2.0
58 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 4: PERFORMANCE PARAMETERS OF A CONTROL SYSTEM
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
59 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
Lab Session 5:
OBJECTIVES:
The objective of this experiment is to show how a permanent-magnet DC motor
may be controlled by varying the magnitude and direction of its armature
current and recognize its torque/speed characteristics.
DELIVERABLES:
A complete lab report including the following:
61 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
To derive a mathematical model for the motor under discussion, consider the
schematic shown in figure 5.2. As we know that a motor is an electro-
mechanical device so its mathematic model consists of two differential
equations each representing one of its aspects.
( ) (5.1)
( ) (5.2)
62 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
When the motor rotates and produces a torque as given in equation 5.1, there
emerges a retarding torque, because of friction, in response to . If we assume
the friction to be viscous friction, as we assumed for the case of mass-spring
model in previous labs, we get
( ) (5.3)
Newton’s second law of motion, when translated into angular mechanics, takes
the following form.
∑ ( ) (5.4)
Here is moment of inertia and ( ) is angular acceleration. Putting value we
get
( )
( ) (5.5)
Or,
( )
( ( ) ( )) (5.6)
Equation 5.6 is the mechanical equation for an armature-controlled DC motor.
Now we turn to the electrical aspect of this motor. Applying Kirchhoff’s Voltage
Law to figure 5.2, we get,
( )
( ) (5.7)
Substituting equation 5.2 and rearranging the terms gives,
63 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
( )
( ( ) ( )) (5.8)
Equation 5.8 gives electrical equation of the motor. Combining these two
equations results in a complete model of armature-controlled DC motor.
instructor if you stuck anywhere. Your final model should look like the one
shown in figure 5.3.
Once the model is built, save it and run the following commands on MATLAB
command window.
>> J=3.2284E-6;
>> b=3.5077E-6;
>> Kt=0.0274;
>> Kb = 0.0274;
>> R=4;
>> L=2.75E-6;
64 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
Now run the simulation (Ctrl-t or Start on the Simulation menu). When the
simulation is finished, double-click on the scope and hit its autoscale button.
Save your file as "DCmotor.mdl" (or any other name of your liking). MATLAB will
extract the linear model from the saved model file, not from the open model
window. At the MATLAB prompt, enter the following commands:
>> [A,B,C,D]=linmod('motormodel')
>> [num,den]=ss2tf(A,B,C,D)
>> sys = tf(num,den)
To verify the model extraction, you may generate an open-loop step response of
the extracted transfer function in MATLAB. Enter the following command.
>> step(sys)
65 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
We can encapsulate the whole Simulink model designed above in a single block
to be used as a component in subsequent designs. It enables us to abstract
unnecessary details of a subsystem and let us work with the block through its
interface only. To do so, remove the input(s) and output(s) of a Simulink model
and replace them with In and Out blocks. Now select the whole system and hit
on Create Subsystem option from Edit menu. Alternatively, you may right
click on the selected model and select Create Subsystem from the menu. The
complete model will be housed in a single block with input(s) and output(s)
going in and coming out of it as shown in figure 5.4.
Next, we need to set the parameters of this subsystem. To do this, select the
subsystem and click on Mask Subsystem from Edit menu. The following
window will appear as a result.
66 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
Select the Parameter tab and then click on the Add icon on top right corner of
the window. It will add a new parameter entry in Dialog Parameters table.
Write the name of the parameter, for your own reference, in prompt field and
give the very same variable as used in the model for this parameter in
variable field. Continue to declare all the parameters used in the design.
When finished, click on the Apply button and close the window.
Our model is now ready to use. Just double click on it to initialize the
parameter values and use it in any bigger system as a component. The
initialization window looks like the one shown below.
Apply step input to this block to verify that it gives the same output as
obtained from the original design.
67 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
EXERCISE 1:
Fill the following table for the DC Motor design developed above.
1 -1
2 -2
3 -3
4 -4
EXERCISE 2:
Interpret the results obtained in exercise 1 and draw a conclusion as to how to
control angular velocity and direction of rotation of an armature-controlled DC
motor.
EXERCISE 3:
Apply a 5V sinusoid signal with 50 Hz frequency to this model and observe
velocity and displacement response of the motor. Explain the motor response in
transient phase i.e. before 0.05 sec.
68 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 5: DC MOTOR CHARACTERISTICS
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
69 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
Lab Session 6:
CHARACTERISTICS OF
FEEDBACK CONTROL SYS TEM
PRE REQUISITES:
Students should have firm understanding of performance parameters and
simulation of systems against various inputs.
OBJECTIVES:
The objective of this exercise will be to study the effects of feedback on the
response of the system to step input and step disturbance taking the practical
example of English Channel boring machine and design a control system
taking into account performance measurement.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
We use feedback in a control system to
71 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
with two examples. As always, our prime focus would be to emphasis the use of
MATLAB in the control system analysis.
Write the following script in an m-file and run it. You will get the response
shown in figure 6.2.
clc, clf
R = 1;
Kt = 10; Kb = 0.1;
b = 0.5; J = 2;
[yo,t] = step(sys);
plot(t,yo)
title('Open-Loop Disturbance Step Response')
xlabel('Time (sec)'), ylabel('Speed'), grid
yo(length(t))
73 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
Since our desired value of ( ) is zero because we haven’t applied any input
voltage ( ( ) = 0), the steady-state error is just the final value of ( ), which we
denote by ( ) to indicate open-loop. The steady-state error, shown on the plot
in figure 6.2, is approximately the value of the speed when t = 7 sec. We can
obtain an approximate value of the steady-state error by looking at the last
value in the output vector , which we generated in the process of making the
plot of figure 6.2. The approximate steady-state value of is
( ) ( ) rad/sec
As before, the steady-state error is just the final value of ( ), which we denote
by ( ) to indicate closed-loop. The disturbance response is shown in figure
6.4. We might need following additional parameter values to generate this plot.
( ) ( ) rad/sec
74 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
From figure 6.4 it is evident that not only the steady-state error has been
greatly reduced, but also the settling time of the system has decreased from
approximately 7 seconds to almost 0.02 seconds.
The machines operated from both ends of the channel and bored towards the
middle. To link up accurately in the middle of the channel, a laser guidance
system kept the machines precisely aligned. A model of the boring machine
control is shown in the figure 6.5, where ( ) is the actual angle of direction of
75 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
travel of the boring machine and ( ) is the desired angle. The effect of load on
the machine is represented by the disturbance ( ).
The response of the closed-loop system to both the inputs, considering them
simultaneously, can be given as
( ) ( ) ( )
The effect of the control gain K on the transient response is shown in figure 6.6
along with the script used to generate the plot.
den = [1 12 0];
t = 0:0.05: 2;
[y1,t] = step(sys1,t);
[y2,t] = step(sys2,t);
[y3,t] = step(sys3,t);
subplot(3,1,1)
plot(t,y1)
title('Step Response for K = 50')
xlabel('Time (sec)')
ylabel('Y(s)')
76 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
grid
subplot(3,1,2)
plot(t,y2)
title('Step Response for K = 100')
xlabel('Time (sec)')
ylabel('Y(s)')
grid
subplot(3,1,3)
plot(t,y3)
title('Step Response for K = 200')
xlabel('Time (sec)')
ylabel('Y(s)')
grid
Comparing the three plots in figure 6.6, it can be seen that increasing K
increases the overshoot. Although it may not be obvious from the plot in figure
6.6, it is also true that increasing K decreases the settling time. This can be
verified by taking a closer look (at the command level) at the data used to
generate the plot. This example demonstrates how the transient response can
be altered by feedback control gain K. based on our analysis thus far, we would
prefer to use K = 50. However, there are other considerations that must be
taken into account before we can establish the final design.
77 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
Before making the final choice for K, it is important to consider the system
response to a unit step disturbance. This is shown in figure 6.7. We see that
increasing K reduces the steady-state response of Y(s) to the step disturbance.
The steady-state value of Y(s) is 0.02, 0.01, and 0.005 for K=50, 100, and 200
respectively.
Note that the steady-state values are predicted from the final value theorem as
follows:
( )
( )
78 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
( )
( ) ( )
Here G(s) is the plant and C(s) is the controller which is equal to K in our given
example. We can compute the value of S(s) for different values of s and
generate a plot of system sensitivity. For low frequency, we can approximate
the system sensitivity by
( )
Above equation shows that increasing the gain K reduces the system
sensitivity.
79 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
EXERCISE 1:
For the motor system given below, you need to design feedback such that the
overshoot is limited and there is less oscillatory nature in the response based
on the specifications provided below. Assume no disturbance.
Use MATLAB, to find the system performance for different values of Ka and find
which value of the gain Ka satisfies the design conditions specified. Use the
following table.
Ka 20 40 60 80 100
PO
Ts
EXERCISE 2:
Consider the system given below.
80 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
c) Generate the system response; for K= 10, 20, 50, 100; due to a unit step
input, r(t)
d) Generate the system response; for K= 10, 20, 50, 100; due to a unit step
disturbance, d(t)
e) For each case find the percentage overshoot, rise time, settling time,
steady state of y(t)
81 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 6: CHARACTERISTICS OF FEEDBACK CONTROL SYSTEM
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
82 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
Lab Session 7:
OBJECTIVES:
The objective of this exercise is to verify the Routh-Hurwitz stability criterion
studied in theory class. Furthermore, this RH criterion will be exploited to find
the region of stability of any linear system.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
The stability of a closed-loop control system is a fundamental issue in control
system. Generally speaking, an unstable closed-loop control system is of little
practical value. For linear systems, a necessary and sufficient condition for a
feedback control system to be stable is that all the poles of the system transfer
function have negative real parts. In other words, the poles must lie in the left-
half plane for the system to be stable. The Routh-Hurwitz stability method
provides a structured mechanism for determining the number of unstable poles
of the closed-loop characteristic equation. This allows us to obtain a yes or no
answer to stability without explicitly calculating the values of poles.
83 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
easy and accurate method for computing the poles of the characteristic
equation.
( )
associated with the closed-loop control system shown in figure 7.1(a). The
corresponding Routh-Hurwitz array is shown in figure 7.1(b).
The two sign changes in the first column of figure 7.1(b) indicate that there are
two roots of characteristic polynomial in the right-half plane; hence the closed-
loop system is unstable. Using MATLAB we can verify the Routh-Hurwitz results
by directly computing the roots of the characteristic equation, as shown below.
84 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
ans =
-3.0000
1.0000 + 2.6458i
1.0000 - 2.6458i
( )
k = 0:0.5:20;
for i = 1 : length(k)
q = [1 2 4 k(i)];
p(:,i) = roots(q);
end
plot(real(p),imag(p),'x'), grid
xlabel('Real Axis'), ylabel('Imaginary Axis')
85 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
In order to steer a tracked vehicle, it is necessary to drive one track faster than
the other, causing the vehicle to turn toward the slower track. This is called
skid steering or differential steering. While the theory is simple, its execution is
86 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
The design of a turning control for a tracked vehicle involves the selection of
two parameters. Figure 7.4 shows model of steering control of a two-track
vehicle. The two tracks are operated at different speeds in order to turn the
vehicle. We must select K and a so that the system is stable and the steady-
state error for a ramp command is less than or equal to 24% of the magnitude
of the command.
If we denote controller transfer function with C(s) and power train plus vehicle
transfer function with G(s) then the characteristic equation of this feedback
system is
( ) ( )
or
( )
Using the Routh-Hurwitz array we determine that for this system to be stable,
we require that
( )( )
The following code helps determine the suitable combinations of K and a that
satisfy the abovementioned conditions and result in stable system.
a = [0.1 : 0.01 : 3.0];
k = [20 : 120];
x = 0*k; y = 0*k;
n = length(k);
m = length(a);
87 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
for i = 1 : n
for j = 1 : m
q = [1, 8, 17, k(i)+10, k(i)*a(j)];
p = roots(q);
if max(real(p)) > 0
x(i) = k(i);
y(i) = a(j-1);
break;
end;
end
end
plot(x,y)
grid, xlabel('K'), ylabel('a')
title('Stability Region for Two-Track Vehicle Steering Control')
The plot in figure 7.5 shows the outcome of this code. Note that the region to
the left of the plot of a versus K is the stable region, since that corresponds to
.
where
( ) ( )
Therefore, we have
88 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
or
Any values of a and K that lie in the stable region in figure 7.5 and satisfy
above equation will lead to an acceptable design. For example, and
will satisfy all the design requirements. The closed loop transfer
function will then be
( )
The corresponding unit ramp response is shown in figure 7.6 below. The
steady-state error is less than 0.24 as desired.
89 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 7: STABILITY OF CONTROL SYSTEM
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
90 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
Lab Session 8:
OBJECTIVES:
This lab aims to facilitate the students in drawing root locus of any given
system quickly, easily and precisely using MATLAB. It also expects the students
to develop an insight as how the system will behave if the gain is varied. The
ultimate objective of this lab is to enable the students to design proportional-
gain controller, in compliance with the performance parameters set forth.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
In the previous lab session, we discussed absolute stability of a closed-loop
feedback control system using Routh-Hurwitz method. We also studied how the
performance of a feedback system can be described in terms of the location of
the roots of the characteristic equation in the s-plane. We know that the
response of a closed-loop feedback control system can be adjusted to achieve
the desired performance by judicious selection of one or more system
parameters. It is, therefore, very useful to determine how the roots of the
characteristic equation move around the s-plane as we change one parameter.
91 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
The Root Locus method, as the name suggests, looks at the loci of the roots as
some parameter of interest, within the system, is varied. Since we already know
that the position of the roots of the characteristic equation strongly influence
the step response of the system, we can find values of the parameter which will
position the roots appropriately, using the method of Root Locus. This method
involves root locus diagrams which the students are expected to have learnt in
the theory class. In this lab we will use MATLAB’s powerful computing capability
to find and trace root locus of a given system.
( )
( )( )
>> rlocus(num,den)
Here num is array of open-loop numerator coefficients and den is array of open-
loop denominator coefficients. Using this command, the root locus is plotted on
the figure window as shown in figure 8.2. The gain vector K is automatically
determined and contains all the gain values for which the closed-loop poles are
to be computed. However, we can define vector K as per our own will and
provide it to rlocus command as
92 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
[r,k] = rlocus(num,den)
[r,k] = rlocus(num,den,k)
[r,k] = rlocus(sys)
the command window will show the matrix r and gain vector K. The columns of
matrix r are equal to length of K and its rows are den-1, containing the
complex root locations. Each row of the matrix corresponds to a gain from
vector K. We can then plot the loci by using the plot command
>> plot(r,’-’)
supplies its own set of gain values used to calculate a root locus plot. The
following example illustrates this point in rather detail.
( )
( )( )
Entering the following code in the MATLAB results in the plot shown in figure
8.3.
num = [ 0 0 0 0 1 ];
den = [ 1 1.1 10.3 5 0];
r = rlocus(num,den);
plot(r,’o’)
axis([-6 6 -6 6])
grid;
94 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
shown in figure 8.4. From this plot it is clear that the two branches, that
approach each other, do not actually touch.
num = [ 0 0 0 0 1 ];
den = [ 1 1.1 10.3 5 0];
K1 = 0 : 0.2 : 20;
K2 = 20: 0.1 : 30;
K3 = 30: 5.0 : 1000
K = [K1 K2 K3];
r = rlocus(num,den,K);
plot(r,’o’)
axis([-4 4 -4 4])
grid;
Since the root locus is actually the locations of all possible closed-loop poles,
from the root locus we can select a gain such that our closed-loop system will
95 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
perform the way we want. If any of the selected poles is on the right half plane,
the closed-loop system will be unstable. The poles that are closest to the
imaginary axis have the greatest influence on the closed-loop response, so even
though the system has three or four poles, it may still act like a second or even
first order system depending on the location(s) of the dominant pole(s).
In other words, lines of constant damping ratio are radial lines passing through
the origin as shown in figure 8.5. For example, a damping ratio of 0.5 requires
that the complex poles lie on the lines drawn through the origin making angles
of ± 60o with negative real axis. If the real part of a pair of complex poles is
positive, which means that the system is unstable, the corresponding ζ is
negative. The damping ratio determines the angular location of the poles, while
the distance of the pole from the origin is determined by the undamped natural
frequency . The constant loci are circles.
sgrid
axis ([-2 2 -2 2])
axis ('square')
title ('Constant \zeta Lines and Constant \omega_n Circles')
xlabel ('Real Axis')
ylabel('Imaginary Axis')
96 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
Enter the following code into MATLAB and show that the resulting plot is similar
to the one shown in figure 8.5.
num = [ 0 0 0 1 ]
den = [ 1 4 5 0 ]
axis ('square')
rlocus (num , den)
axis ([- 3 1 -2 2])
sgrid ([0.5 , 0.707],[0.5 , 1.0 , 1.5])
title ('Root Locus Plot with \zeta = 0.5 and 0.707 Lines and
\omega_n = 0.5, 1.0 and 1.5 Circles')
97 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
sgrid (0.5,[])
( ) ( )
( )
( ) ( )( )( )
We want to design a feed-back controller for the system by using the root locus
method and our design criteria are 5% overshoot and 1 second rise time.
num=[1 7];
den=conv(conv([1 0],[1 5]),conv([1 15],[1 20]));
rlocus(num,den)
axis([-22 3 -15 15])
The plot shows all possible closed-loop pole locations for a pure proportional
controller. Obviously not all of those closed-loop poles will satisfy our design
criteria. To determine what part of the locus is acceptable, we can use the
command sgrid(Zeta,Wn) to plot lines of constant damping ratio and natural
frequency. In our problem, we need an overshoot less than 5% (which means a
damping ratio greater than 0.7 and a rise time of 1 second (which means a
natural frequency greater than 1.8. Append the code given above with the code
given below.
zeta=0.7;
Wn=1.8;
sgrid(zeta, Wn)
On the plot, the two white dotted lines at about a 45 degree angle indicate pole
locations with ζ = 0.7; in between these lines, the poles will have ζ > 0.7 and
outside of the lines ζ < 0.7. The semicircle indicates pole locations with a
98 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
natural frequency = 1.8; inside the circle, < 1.8 and outside the circle
> 1.8.
Going back to our problem, to make the overshoot less than 5%, the poles have
to be in between the two white dotted lines, and to make the rise time shorter
than 1 second, the poles have to be outside of the white dotted semicircle. So
now we know only the part of the locus outside of the semicircle and in
between the two lines are acceptable. All the poles in this location are in the
left-half plane, so the closed-loop system will be stable.
From the plot we see that there is part of the root locus inside the desired
region. So in this case we need only a proportional controller to move the poles
to the desired region. You can use rlocfind command in MATLAB to choose the
desired poles on the locus.
[k,poles] = rlocfind(num,den)
Click on the plot the point where you want the closed-loop pole to be.
Note that since the root locus may have more than one branch, when you
select a pole, you may want to find out where the other pole(s) are. Remember
they will affect the response too. From the plot we should make sure that all
the poles selected (all the red "+") are at reasonable positions only then we can
go ahead and use the chosen K as our proportional controller.
99 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
In order to find the step response, we need to know the closed-loop transfer
function. We could compute this using the rules of block diagrams, or let
MATLAB do it for us:
The two arguments to the tf command are the numerator and denominator of
the open-loop system. We need to include the proportional gain that we have
chosen. Unity feedback is assumed in this case.
The step response of this closed-loop system can be computed to see if our
design meets the desired criteria:
step(sysCL)
As we expected, this response will have an overshoot less than 5% and a rise
time less than 1 second.
The selected point for the response shown above has K = 511.5287 and the
system’s poles corresponding to this K are
-22.6275
-11.4095
-2.9815 + 2.2317i
-2.9815 - 2.2317i
100 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
( ) ( )
( )
( )
101 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
EXERCISE 1:
1
GP ( s)
s( s 3)(s 5)
For this plant a controller must be designed, such that the step response of the
closed loop shows the following properties:
EXERCISE 2:
Lasers can be used to drill the hip socket for the appropriate insertion of an
artificial hip joint. The use of the laser surgery requires high accuracy for
position and velocity response. Let us consider the system shown below which
uses a DC motor manipulator for the laser.
The amplifier gain K must be adjusted so that the steady state error for a ramp
input, r(t) = At (where A = 1mm/s), is less than or equal to 0.1 mm, while a
stable response is maintained.
To Obtain the steady-state error required and a good response, we select motor
with a field time constant τ1 = 0.1 sec and a motor-plus-load time constant τ2 =
0.2 sec.
a) Find the value of K for which ess is less than 0.1 mm. Expression for ess
for ramp input is
ess =
b) Find the rang of K for which the system is stable using root locus.
c) Apply a ramp input and observe the output for t = 0 sec to t = 6 sec
102 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 8: THE ROOT LOCUS METHOD
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
103 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
Lab Session 9:
OBJECTIVES:
The primary objective of this lab is to present procedures for the design and
compensation of single-input-single-output linear time-invariant control
systems using Root Locus approach.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
It is often possible to achieve stability and satisfactory system performance by
adjusting the gain of the system. We discussed many examples in the previous
labs illustrating design by adjusting one or two parameters. However, in many
practical cases the adjustment of gain alone may not provide sufficient
alteration of the system behavior to meet the given specifications. As is
frequently the case, increasing the gain value will improve steady-state
behavior but will result in poor stability or even instability. It is then necessary
to redesign the system (by modifying the structure or by incorporating
additional devices and components) to tailor the overall behavior so that the
system will behave as desired. Such a redesign or addition of a suitable device
is called compensation.
105 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
The design via root locus method is based on reshaping the root locus of the
system by adding poles and zeros to the system’s open-loop transfer function
and forcing the root loci to pass through desired closed-loop poles in the s-
plane. This design approach is based on the assumption that the closed-loop
system has a pair of dominant closed-loop poles.
Normally, cascade (or series) compensation may be simpler than feedback (or
parallel) compensation; however, series compensation frequently requires
106 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
additional amplifiers to increase the gain and/or to provide isolation. Note that,
in general, the number of components required in parallel compensation will be
less than the number of components in series compensation, provided a
suitable signal is available. In this lab we will discuss series compensation in
detail.
107 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
pair of dominant closed-loop poles can be placed at the desired location. Often,
the damping ratio and undamped natural frequency of a pair of dominant
closed-loop poles are specified.
A first-order lead compensator can be designed using the root locus. The
transfer function of a lead compensator is given by
( )
How is this accomplished? If you recall finding the asymptotes of the root locus
that lead to the zeros at infinity, the equation to determine the intersection of
the asymptotes along the real axis is:
∑ ∑
( ) ( )
108 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
109 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
The system is shown in figure 9.2. A steel ball is rolling on top of a long beam.
The beam is mounted on the output shaft of an electric motor and so the beam
can be tilted about its center axis by applying an electrical control signal to the
motor amplifier. The position of the ball on the beam can be measured using a
special sensor.
The control job is to automatically regulate the position of the ball on the beam
by changing the angle of the beam. This is a difficult task because the ball does
not stay in one place on the beam but moves with an acceleration that is
proportional to the tilt of the beam. In control technology this system is open-
loop unstable because the system output (the ball position) increases without
limit for a fixed input (beam angle). Feedback control must be used to keep the
ball in desired position on the beam.
The complete description of the dynamics of the ball rolling on the beam is
quite complicated and for control system perspective a simplified derivation is
used to give a model that is good for controller design.
The force that accelerates the ball as it rolls on the beam comes from the
component of gravity that acts parallel to the beam. The dotted line in figure
9.3 shows this force to be . The ball actually accelerates along the beam
by rolling, but we can simplify the derivation by assuming that the ball is
sliding without friction along the beam. Then, using the second law of Newton,
the simplified ball and beam model is,
110 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
where m is the mass of the ball, g is the gravitational constant, is the beam
angle and x is the position of the ball on the beam.
This simple model of the ball and beam is a good approximation to the true
system dynamics, and is the one normally used in text books and design
studies for controller design. Combining actuator and sensor constants with
the gravity constant, we get a single constant b. This represents the overall
gain of the response from control voltage input to measured output
acceleration. The transfer function representation of the above equation is
( )
( )
where
( )
Let’s now set the design criteria and system parameter of this problem as,
The main idea of the root locus design is to estimate the closed-loop response
from the open-loop root locus plot. By adding zeroes and/or poles to the
111 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
original system (adding a compensator), the root locus and thus the closed-loop
response will be modified. Let us first view the root locus for the plant in open-
loop. Create an m-file with the following MATLAB code in order to model the
plant and plot the root locus.
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
K = (m*g*d)/(L*(J/R^2+m)); %simplifies input
num = [-K];
den = [1 0 0];
plant=tf(num,den);
rlocus(plant)
The following root locus plot is generated as a result of the above code.
As you can see the system has two poles at the origin which go off to infinity
along the imaginary axes.
Now we plot the design criteria on the root locus using sgrid command and
the following formulae.
112 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
sgrid(0.70, 1.9)
axis([-4 4 -4 4])
The area between the two dotted diagonal lines represents locations where the
percent overshoot is less than 5%. The area outside the curved line represents
locations where the settling time is less than 3 seconds. Note that no region of
the plot falls within the design criteria shown by these lines. To remedy this
and bring the root locus into the left-hand plane for stability we will try adding
a lead-compensator to the system.
A first order lead compensator tends to shift the root locus into the left-hand
plane. We will position the zero near the origin to cancel out one of the poles.
The pole of our compensator will be placed to the left of the origin to pull the
root locus further into the left-hand plane. Add the following lines of MATLAB
code to your m-file.
113 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
p = 5;
z = 0;
contr=tf([1 z],[1 p]);
rlocus(contr*plant)
sgrid(0.70, 1.9)
You can see that the branches of the root locus are within our design criteria.
Now that we have moved the root locus into the left-hand plane, we may select
a gain that will satisfy our design requirements. We can use the rlocfind
command to help us do this.
[k,poles]=rlocfind(contr*plant)
Go to the plot and select a point in the desired region. You will get a value of K
corresponding to the point you selected on the s-plane. This value of K can be
114 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
put into the system and the closed-loop response to a step input of 0.25 m can
be obtained.
sys_cl=feedback(k*contr*plant,1);
t=0:0.01:5;
figure(1)
step(sys_cl,t)
Run the code and get the output. From this plot we see that when a 0.25 m
step input is given to the system, both the settling time and percent overshoot
design criteria are met.
( )
How does the lag controller shift the root locus to the right? The answer is the
same as that to lead compensator. Again recall finding the asymptotes of the
root locus that lead to the zeros at infinity, the equation to determine the
intersection of the asymptotes along the real axis is
∑ ∑
( ) ( )
When a lag compensator is added to a system, the value of this intersection will
be a smaller negative number than it was before. The net number of zeros and
poles will be the same (one zero and one pole are added), but the added pole is
a smaller negative number than the added zero. Thus, the result of a lag
compensator is that the asymptotes' intersection is moved closer to the right-
half plane, and the entire root locus will be shifted to the right.
115 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
It was previously stated that that lag controller should only minimally change
the transient response because of its negative effect. If the phase-lag
compensator is not supposed to change the transient response noticeably,
what is it good for? The answer is that a phase-lag compensator can improve
the system's steady-state response. It works in the following manner. At high
frequencies, the lag controller will have unity gain. At low frequencies, the gain
will be z/p which is greater than 1. This factor z/p will multiply the position,
velocity, or acceleration constant (Kp, Kv, or Ka), and the steady-state error will
thus decrease by the factor z/p.
̇
( )( )
J=0.01;
b=0.1;
116 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
K=0.01;
R=1;
L=0.5;
num=K;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
motor=tf(num,den);
rlocus(motor)
sgrid(.8,2.5)
Remember that, we need the settling time and the overshoot to be as small as
possible. Large damping corresponds to points on the root locus near the real
axis. A fast response corresponds to points on the root locus far to the left of
the imaginary axis. To find the gain corresponding to a point on the root locus,
we can use the rlocfind command. We can find the gain and plot the step
response using this gain all at once. To do this, enter the following commands
at the end of your m-file and rerun it.
[k,poles] = rlocfind(motor)
sys_cl=feedback(k*motor,1);
t=0:0.01:3;
step(sys_cl,t)
117 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
Go to the plot and select a point on the root locus half-way between the real
axis and the damping requirement, say at -6 + 3i. You should also take step
response with the K found by rlocfind. Figure 9.8 shows root locus of
uncompensated system whereas transient response of the system with K = 10
is shown in figure 9.9.
As you can see, there is no overshoot and the settling time is about one second,
so the overshoot and settling time requirements are satisfied. The only problem
we can see from this plot is the steady-state error of about 50%. If we increase
the gain to reduce the steady-state error, the overshoot becomes too large (Try
this yourself). We need to add a lag controller to reduce the steady-state error.
From the plot we see that this is a very simple root locus. The damping and
settling time criteria were met with the proportional controller. The steady-state
error is the only criterion not met with the proportional controller. A lag
compensator can reduce the steady-state error. By doing this, we might,
however, increase our settling time. The procedure to design a lag controller for
a specific system is laid down here.
The formula to calculate the positions of lag compensator’s pole and zero is
Note that this Kp is position gain and it’s not the same as open-loop gain K.
Now, our current steady-state error, from figure 9.9, is 0.5 or 50%, so our Kp,old
will be,
And we want to reduce our error to less than 0.01, or 10%, so Kp,new will be,
Now, assume any reasonable arbitrary value, near to origin, for compensator
pole, say 0.01, and find the location of compensator zero using the formula,
We have selected open-loop gain to be 12. As you can see from figure 9.10 that
the step response is not quite satisfactory. You may also note that even though
the gain was selected to correlate with a position close to the damping criterion,
the overshoot is not even close to five percent. This is due to the effect of the
lag controller; its pole is much slower. What this means is that we can go
beyond the dotted lines that represent the limit, and get the higher gains
without worrying about the overshoot. Rerun your m-file; place the gain just
above the white, dotted line. Keep trying until you get a satisfactory response.
It should look similar to the one shown in figure 9.11(we have used open-loop
gain to be 48).
119 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
The steady-state error is smaller than 1%, and the settling time and overshoot
requirements have been met. As you can see, the design process for root locus
is very much a trial and error process. That is why it is nice to plot the root
locus, pick the gain, and plot the response all in one step. If we had not been
able to get a satisfactory response by choosing the gains, we could have tried a
different lag controller, or even added a lead controller.
120 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
EXERCISE 1:
Design a Compensator to tailor the transient response as per the given criteria
EXERCISE 2:
You would notice that although the transient response of the above system is
adapted as per the given specifications, yet its steady-state error is beyond any
tolerance range. Now design another compensator and cascade it with the
previous one to reduce the steady-state error to less than 5 %.
Note: Exercise 1 and 2 employ both lead compensator and lag compensator on a
plant. Such controller that compensates both lead effect and lag effect is called
lead-lag compensator.
EXERCISE 3:
Design Simulink model of the system given above. Apply both lead and lag
compensator in cascaded fashion to the plant validate the results obtained in
exercise 1 and 2.
121 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 9: CONTROLLER DESIGN VIA ROOT LOCUS
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
122 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
INTRODUCTION TO PID
CONTROLLERS
PRE REQUISITES:
This lab is quite independent in a sense that it does not require any specific
background knowledge except elementary fundamentals of control theory.
However, a little understanding of compensators discussed in the last lab may
help comprehend the depth and breadth of PID rather rigorously.
OBJECTIVES:
The objective of this lab is to study the three term (PID) controller and its
effects on the feedback loop response. We will investigate the characteristics of
each of proportional (P), integral (I), and derivative (D) controls, and learn how
to use them to obtain a desired response.
DELIVERABLES:
A complete lab report including the following:
INTRODUCTION:
A proportional–integral–derivative controller (PID controller) is the most
commonly used feedback controller in industrial control systems. A PID
controller calculates an error value as the difference between measured output
and a desired setpoint. The controller attempts to minimize the error by
adjusting the process control inputs.
123 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
here,
Kp = Proportional Gain
Ki = Integral Gain
Kd = Derivative Gain
First, let’s take a look at how the PID controller works in a closed-loop system
using the schematic shown below.
The signal e(t) represents the tracking error, the difference between the
reference input r(t) and the actual output y(t). This error signal will be sent to
the PID controller, and the controller computes both the derivative and integral
of this error signal. The signal u(t) just past the controller is now equal to the
proportional gain (Kp) times the magnitude of the error signal plus the integral
gain (Ki) times the integral of the error signal plus the derivative gain (Kd) times
the derivative of the error signal.
( )
( ) ( ) ∫ ( )
124 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
This signal, u(t), will now be sent to the plant, and the new output, y(t), will be
obtained. This new output will be sent back to the sensor again to find the new
error signal. The controller takes this new error signal and computes its
derivative and it’s integral again. This process goes on and on.
Note that these correlations may not be exactly accurate, because Kp, Ki, and
Kd are dependent on each other. In fact, 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 taking Laplace transform and solving for the transfer function between the
displacement X(s) and the input Fa(s), we get
( )
( )
125 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
M=1 kg
b = 10 N.s/m
k = 20 N/m
Fa(s) = 1 N
( )
( )
The goal of this problem is to show how each of Kp, Ki, and Kd contribute to
obtain
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];
plant=tf(num,den);
axis('square')
step(plant)
Running this m-file in the MATLAB command window should give you the plot
shown in figure 10.2.
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of
the output to a unit step input. This corresponds to the 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. Let's design a controller that will reduce
the rise time, reduce the settling time, and eliminates the steady-state error.
PROPORTIONAL CONTROL:
From the table shown above, 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:
126 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
( )
( ) ( )
Let the proportional gain (Kp) equals 300 and change the m-file to the following:
Kp=300;
contr=Kp;
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Running this m-file in the MATLAB command window should give you the
following plot.
127 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
The above plot shows that the proportional controller reduced both the rise
time and the steady-state error, increased the overshoot, and decreased the
settling time by small amount.
Now, let's take a look at a PD control. From the table shown 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:
( )
( ) ( ) ( )
Let Kp equals 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;
contr=tf([Kd Kp],1);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
128 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
This plot shows that the derivative controller reduced both the overshoot and
the settling time, and had a small effect on the rise time and the steady-state
error.
Before going into a PID control, let's take a look at a PI control. From the table,
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:
( )
( ) ( )
Let's reduce the Kp to 30, and let Ki equals 70. Modify your code as follows,
Kp=30;
Ki=70;
contr=tf([Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
129 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
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 steady-state error.
Now, let's take a look at a PID controller. The closed-loop transfer function of
the given system with a PID controller is:
( )
( ) ( ) ( )
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. You should get the following step
response.
Kp=350;
Ki=300;
Kd=50;
contr=tf([Kd Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
130 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
Lastly, keep in mind that you do not need to implement all three controllers
(proportional, derivative, and integral) into a single system, if not necessary.
For example, if a PI controller gives a good enough response (like the above
example), then you don't need to implement a derivative controller on the
system. Keep the controller as simple as possible.
( )
( ) ( )
The block diagram for this example with a controller and unity feedback of the
ball’s position is shown in figure 10.7. First, we will study the response of the
system shown above when a proportional controller is used. Then, derivative
and/or integral control will be added, if necessary.
131 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
K = (m*g*d)/(L*(J/R^2+m)); %simplifies input
num = [-K];
den = [1 0 0];
ball=tf(num,den);
kp = 1;
sys_cl=feedback(kp*ball,1);
Now, we can model the system's response to a step input of 0.25 m. Add the
following line of code to your m-file and run it:
t = 0:0.5:100
step(0.25*sys_cl,t)
You should get the output as shown in figure 10.8. As, you can see the
addition of proportional gain does not make the system stable. Try changing
132 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
Now, we will add a derivative term to the controller. Copy the following lines of
code to an m-file and run it to view the system's response to this control
method.
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
K = (m*g*d)/(L*(J/R^2+m)); %simplifies input
num = [-K];
den = [1 0 0];
ball=tf(num,den);
kp = 10;
kd = 10;
contr=tf([kd kp],1);
sys_cl=feedback(contr*ball,1);
t=0:0.01:5;
step(0.25*sys_cl)
Now the system is stable but the overshoot is much too high and the settling
time needs to go down a bit. From the table given in section 10.1.1, we see that
by increasing Kd we can lower the overshoot and decrease the settling time
slightly. Therefore experiment with the value of Kd and find such differential
133 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
gain that reduces the overshoot below 5%. Furthermore fine tune Kp to reduce
the settling time. The figure below shows the system response for Kp = 15 and
Kd = 40.
As you can see from the above plot all the control objectives have been met
without the use of an integral controller (settling time for this example is
considered achieved when the response is less than 2% of its final value).
Remember, that for a control problem there is usually more than one solution
for the problem.
134 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
EXERCISE 1:
( )
( )
EXERCISE 2:
̇
( )( )
EXERCISE 3:
(( )( ) )
135 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
̇
( )( )
136 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering
Lab Session 10: INTRODUCTION TO PID CONTROLLERS
Evaluation Chart
Viva 2
Discipline 2
Total 10
_______________________ _______________________
137 | P a g e
COMSATS Institute of Information Technology, Lahore Department of Electrical Engineering