Vous êtes sur la page 1sur 156

FEEDBACK CONTROL SYSTEM

LAB # 1

Prepared By :
M. Hammad Saleem

NED University of Engineering & Technology


Part I: Introduction to MATLAB
Objective:
 The objective of this exercise will be to introduce you to
the concept of mathematical programming using
MATLAB.
 We shall study how to define variables, matrices etc, see
how we can plot results and write simple MATLAB codes.
Topics
Introduction
MATLAB Environment
Getting Help
Variables
Vectors, Matrices, and Linear Algebra
Plotting
Introduction
Q. What is MATLAB ?
• MATLAB is a computer program that combines computation
and visualization power that makes it particularly useful tool
for engineers.
• MATLAB is an executive program, and a script can be made
with a list of MATLAB commands like other programming
language.
Q. MATLAB Stands for MATrix LABoratory.
• The system was designed to make matrix computation
particularly easy.
Q. The MATLAB environment allows the user to:
• manage variables
• import and export data
• perform calculations
• generate plots
• develop and manage files for use with MATLAB.
Display Windows

This is the work space,


which list all the
variables you are using
This is the command window, you can
enter commands and data and results are
displayed here

This is the command


history window, it
displays a log of the
command used.
Display Windows (con’t…)
 Graphic (Figure) Window
o Displays plots and graphs
o Created in response to graphics commands.

 M-file editor/debugger window


o Create and edit scripts of commands called M-
files.
Getting Help
 Type one of following commands in the
command window:
o help – lists all the help topic

o help topic – provides help for the specified topic

o help command – provides help for the specified command

o help help – provides information on use of the help command

o helpwin – opens a separate help window for navigation

o lookfor keyword – Search all M-files for keyword


Variables
 Variable names:
o Must start with a letter
o May contain only letters, digits, and the underscore “_”
o Matlab is case sensitive, i.e. one & OnE are different variables.

 Assignment statement:
o Variable = number;
o Variable = expression;

 Example:
NOTE: when a semi-colon ”;” is placed
>> tutorial = 1234; at the end of each command, the result
>> tutorial = 1234 is not displayed.
tutorial =
1234
Variables (con’t…)
 Special variables:
o ans : default variable name for the result
o pi: π = 3.1415926…………
o eps: 𝟄 = 2.2204e-016, smallest amount by which 2 numbers can differ.
o Inf or inf : infinity
o NaN or nan: not-a-number

 Commands involving variables:


o who: lists the names of defined variables
o whos: lists the names and sizes of defined variables
o clear: clears all variables, reset the default values of special variables.
o clear name: clears the variable name
o clc: clears the command window
o clf: clears the current figure and the graph window.
Vectors, Matrices and Linear Algebra

 Vectors

 Matrices

 Array Operations

 Solutions to Systems of Linear Equations.


Vectors
o A row vector in MATLAB can be created by an explicit list, starting
with a left bracket, entering the values separated by spaces (or
commas) and closing the vector with a right bracket.
o A column vector can be created the same way, and the rows are
separated by semicolons.
o Example:
>> x = [ 0 0.25*pi 0.5*pi 0.75*pi pi ]
x=
0 0.7854 1.5708 2.3562 3.1416

>> y = [ 0; 0.25*pi; 0.5*pi; 0.75*pi; pi ]


y=
0
0.7854
1.5708
2.3562
3.14
Vectors(con’t…)
o Vector Addressing – A vector element is addressed in MATLAB with an
integer index enclosed in parentheses.
o Example:
>> x(3) 3rd elements of vector x
ans =
1.5708
o The colon notation may be used to address a block of elements.
(start : increment : end)
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.
o Example:
>> x(1:3) 1st to 3rd elements of vector x

ans =
0 0.7854 1.5708
Vectors(con’t…)
Some useful commands
Matrices
 A Matrix array is two-dimensional, having both multiple rows and
multiple columns, similar to vector arrays:
o it begins with [, and end with ]
o spaces or commas are used to separate elements in a row.
o semicolon or enter is used to separate rows.

o Example:
>> 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
Matrices (con’t…)
Some useful commands
Matrices (con’t…)
More commands
Array Operations
 Scalar-array Mathematics
For addition, subtraction, multiplication, and division of an array by a
scalar simply apply the operations to all elements of the array.

o Example:
>> f = [ 1 2; 3 4]
f=
1 2
3 4
>> g = 2*f – 1
g=
1 3 Each element in the array f is multiplied
5 7 by 2, then subtracted by 1.
Solutions to Systems of Linear Equations
 Example: a system of 3 linear equations with 3 unknowns (x1, x2, x3):
3x1 + 2x2 – x3 = 10
- x1 + 3x2 + 2x3 = 5
x1 – x2 – x3 = -1
 Let :

Then, the system can be described as:


Ax = b
Solutions to Systems of Linear Equations
Plotting
 For more information on 2-D plotting, type help graph2d

 Plotting a point:
The function plot () creates a
graphics window, called a Figure
>> plot ( variablename, ‘symbol’) window, and named by default
“Figure No. 1”
o Example : Complex number

>> z = 1 + 0.5j;
>> plot (z, ‘.’)
Plotting (con’t…)
Some useful commands
Plotting (con’t…)
 Plotting Curves:
o plot (x,y) – generates a linear plot of the values of x (horizontal axis) and y
(vertical axis).
o semilogx (x,y) – generate a plot of the values of x and y using a logarithmic
scale for x and a linear scale for y
o semilogy (x,y) – generate a plot of the values of x and y using a linear scale
for x and a logarithmic scale for y.
o loglog(x,y) – generate a plot of the values of x and y using logarithmic scales
for both x and y
Plotting (con’t…)
 Example: (polynomial function)
plot the polynomial using linear/linear scale, log/linear scale, linear/log
scale, & log/log scale: y = 2x2 + 7x + 9
Plotting (con’t…)
 Example: (polynomial function)
plot the polynomial using linear/linear scale, log/linear scale, linear/log
scale, & log/log scale: y = 2x2 + 7x + 9
Plotting (con’t…)
 Adding new curves to the existing graph:
 Use the hold command to add lines/points to an existing plot.
o hold on – retain existing axes, add new curves to current axes. Axes
are rescaled when necessary.
o hold off – release the current figure window for new plots

 Grids and Labels:


Additional commands for Plotting
color of the point Marker of the
or curve data points Plot line styles
FEEDBACK CONTROL SYSTEM

LAB # 1

Prepared By :
M. Hammad Saleem

NED University of Engineering & Technology


Part II: Polynomials in MATLAB
Objective:
 The objective of this session is to learn how to represent
polynomials in MATLAB,
o Find roots of polynomials,
o create polynomials when roots are known and
o Obtain partial fractions.
Polynomial Overview:
 MATLAB provides functions for standard polynomial operations, such as
polynomial roots, evaluation, and differentiation. In addition, there are functions
for more advanced applications, such as curve fitting and partial fraction
expansion.

Polynomial Function Summary


Representing Polynomials
 MATLAB represents polynomials as row vectors containing coefficients ordered
by descending powers. For example, consider the equation

To enter this polynomial into MATLAB, use


>> p = [1 0 -2 -5];

Polynomial Roots
The roots function calculates the roots of a polynomial:
>> r = roots(p)
r=
2.0946
By convention, MATLAB stores roots in column
-1.0473 + 1.1359i
vectors.
-1.0473 - 1.1359i
o The function poly returns to the polynomial coefficients:

>> p2 = poly(r)
p2 =
1 0 -2 -5

o poly and roots are inverse functions,

Polynomial Evaluation
o The polyval function evaluates a polynomial at a specified value.
o To evaluate p at s = 5, use

>> polyval(p,5)

ans =
110
Convolution and Deconvolution
 Polynomial multiplication and division correspond to the operations convolution
and deconvolution.
o The functions conv and deconv implement these operations.
o Consider the polynomials a(s )=s2+2s+3 and b(s )=4s2+5s+6 .
o To compute their product,
>> a = [1 2 3];
>> b = [4 5 6];
>> c = conv(a,b)
c=
4 13 28 27 18
o Use deconvolution to divide back out of the product:

>>[q,r] = deconv(c,a)

q=
4 5 6 b = [4 5 6];
r=
0 0 0 0 0
Polynomial Derivatives
 The polyder function computes the derivative of any polynomial.
o To obtain the derivative of the polynomial.

>>p= [1 0 -2 -5]
>>q = polyder(p)
q=
3 0 -2

 polyder also computes the derivative of the product or quotient of two polynomials.
o For example, create two polynomials a and b:
>>a = [1 3 5];
>>b = [2 4 6];
 Calculate the derivative of the product a*b by calling polyder with a single output argument:
>>c = polyder(a,b)
c=
8 30 56 38
Polynomial Derivatives (con’t…)
 Calculate the derivative of the quotient a/b by calling polyder with two output
arguments:

>>[q,d] = polyder(a,b)
q=
-2 -8 -2
q/d is the result of the operation.
d=
4 16 40 48 36

 polyder also co mputes the derivative of the product or quotient of two polynomials.
o For example, create two polynomials a and b:
Partial Fraction Expansion
 ‘residue’ finds the partial fraction expansion of the ratio of two polynomials.
 This is particularly useful for applications that represent systems in transfer
function form.
 For polynomials b and a,

where o r is a column vector of residues,


o p is a column vector of pole locations, and
o k is a row vector of direct terms.

 Consider the transfer function


>>b = [-4 8]; r= p=
>>a = [1 6 8]; k=
-12 -4
>>[r,p,k] = residue(b,a) []
8 -2
Partial Fraction Expansion (con’t…)
 Given three input arguments (r, p, and k), residue converts back to
polynomial form:

>> [b2,a2] = residue(r,p,k)

b2 =
-4 8
a2 =
1 6 8
FEEDBACK CONTROL SYSTEM

LAB # 1

Prepared By :
M. Hammad Saleem

NED University of Engineering & Technology


Part III: Transfer Function
Objective:
 The objective of this session is:
o Partial Fraction Expansion,
o Transfer Function Representation
o Pole-Zero location of a Transfer Function
1.1. Obtain the partial fractions of the function
F(s) = (s + 1)/ (s2 + s + 1).

close all; The result of the command is;


clear all;
clc; r=
0.5000 - 0.2887i
b=[1 1]; 0.5000 + 0.2887i
a=[1 1 1]; p=
[r,p,k]=residue(b,a) %It finds the -0.5000 + 0.8660i
residues, pole and direct terms of -0.5000 - 0.8660i
a partial fraction expansion of the k=
function F(S). []
o % to verify the outputs obtained above, the transfer function can be
regenerated by using the obtained values of r,p,k.

[b1,a1]=residue(r,p,k)

The result of the command is;


b1 =
1 1
a1 =
1.0000 1.0000 1.0000
1.2. Define the following transfer function G(S) in MATLAB.
G(s) = s (s + 1) (s + 2) / s (s + 3) (s2 + 4s + 8).
close all;
clear all;
clc;
num=[5 15 10];
den=[1 7 20 24 0];
sys=tf(num,den) %generates the transfer function with the
given numerator num and denominator den.

The result of the command is;


Transfer function:
5 s^2 + 15 s + 10
---------------------------
S^4 + 7 s^3 + 20 s^2 + 24 s
1.3. Find the location of the zeros, poles and plot the pole-zero
map of the system, whose transfer function given by;
F(s) = (2s2 + 8s + 6) / (s4 + 6s3 + 12s2 + 24s)
close all;
clear all;
clc;
num=[0 0 2 8 6];
den=[1 6 12 24 0];
[z,p,k]=tf2zp(num,den) % generates the poles, zeros and gain

The result of the command is;

z= p= k=
-3 0 2
-1 -4.5198
-0.7401 + 2.1822i
-0.7401 - 2.1822i

The result specifies that the zeros are at s=-3 and -1, the poles are at
s=0, -4.5198, -0.7401 + 2.1822i and -0.7401 - 2.1822i and the gain is k=2.
o Pole-zero map for this function can be obtained by using the following command.

pzmap(num,den)
1.4) Verify the results obtained for example 1.3 by obtaining the transfer
function from the calculated values of zeros, poles and gain.

close all;
clear all;
clc;
z=[-3; -1];
p=[0; -4.5198; -0.7401 + 2.1822i; -0.7401 - 2.1822i];
k=2;
[n,d]=zp2tf(z,p,k);
printsys(n,d,'s') % prints the transfer function as a ratio of two
polynomials in the transform variable 's'.

The result of the command is


num/den =
2 s^2 + 8 s + 6
-------------------------------
s^4 + 6 s^3 + 12 s^2 + 24s
1.5. Find the Laplace transform of the function
f (t) =e-t (1-sin (t))

clear all;
close all;
clc;
syms t %define the function f(t)
ft=exp(-t)*(1-sin(t));
fs=laplace(ft)

The result of the command is;

fs =
1/(s + 1) - 1/((s + 1)^2 + 1)
1.6) Find the inverse Laplace transform of the function
F(s) =1/(s + 4).

clear all;
close all;
clc;
syms s t %construct symbolic objects for Laplace
transform variable 's' and time variable 't'.
fs=1/(s+4);
ft=ilaplace(fs)

The result of the command is;


ft =
1/exp(4*t)
FEEDBACK CONTROL SYSTEM

LAB # 2

Prepared By :
M. Hammad Saleem

NED University of Engineering & Technology


Objective:

 The objective of this session is:


o Mathematical Modeling of Physical Systems
o MATLAB helps in solving such models
Derive a mathematical model for
Mass-Spring System

o Where;
o According to the laws of physics

o In the case where:

o The differential equation for the above Mass-Spring


system can then be written as follows:

-------------------- (1)

• B is called the friction coefficient and


• K is called the spring constant.
Speed Cruise Control example:
o Assume the spring force Fs(x) =0 which means that K=0.
Equation (1) becomes

------------------------ (3)

Or

------------------------ (4)

Equation (4) is a first order linear ODE.


 Using MATLAB solver ode45 we can write do the following:

1. create a MATLAB-function cruise_speed.m

function dvdt=cruse_speed(t,v)
M=750;
B=30;
Fa=300;
%dv/dt=(Fa/M)-(B/M)v
dvdt=Fa/M-B/M*v;
2. create a new MATLAB m-file and write
v0=0;% (initial speed)
[t,v]=ode45('cruse_speed',[0 200],v0);
plot(t,v);
grid on;
title('cruise speed time response to a constant fraction force Fa(t)')
Mass-Spring System Example:
o Assume the spring force Fs(x) = k xr(t). The mass-spring
damper is now equivalent to

o The second order differential equation has to be decomposed


in a set of first order differential equations as follows
o In vector form, let

o Then the system can be written as;


 The ode45 solver can be now be used:

1. create a MATLAB-function mass_spring.m

function dXdt=mass_spring(t,X)
M=705; % (Kg)
B=30; % (Nsec/m)
Fa=300; % (N)
K=15; % (N/m)
dXdt(1,1)=X(2); % dX/dt
dXdt(2,1)=-B/M*X(2)-K/M*X(1)+Fa/M;
2. In MATLAB write

>> X0=[0; 0]; %(initial position and speed)

>>[t,X]=ode45('mass_spring', [0 200],X0);
MATLAB RESULTS

clear all
close all
clc
X0=[0;0];% (Initial speed and position)
[t,X]=ode45('mass_spring',[0 200],X0);
figure;
plot(t,X(:,1));
xlabel('Time(t)');
ylabel('Position');
title('Mass spring system');
legend('Position ');
grid;
figure;
plot(t,X(:,2),'r');
xlabel('Time(t)');
ylabel('Speed');
title('Mass spring system');
legend('Speed ');
grid;
CONCLUSIONS:
FEEDBACK CONTROL SYSTEM

LAB # 3

Prepared By :
Muhammad
Hammad Saleem
NED University of Engineering & Technology
 The objective of this session is:

o Mathematical modeling of Multiple-Element


Mechanical Translation System
Derive a mathematical model for
Multiple-Element Mechanical Translation System

Where;

o f(t) is applied force to the mass M1.


o B1 and B2 are the viscous friction coefficients indicating the
sliding friction between the masses M1 and M2 and the surface.
Exercise 1:

Write the differential equations for the given Multiple-Element Mechanical


Translation System in terms of the two displacements xa and xb:

o corresponding mechanical network.

o according to the rules for node equations:


Exercise 2:

Obtain the state equations for the system, where xb is the system output.

Let

o The system equations are


 The ode45 solver can be now be used:
1. create a MATLAB-function multiple_element_sys.m
function dXdt=multiple_element_sys (t,X)
Fa=300; %(N)
M1=750; %(Kg)
M2=750; %(Kg)
B1=20; %(Nsec/m)
B2=20; %(Nsec/m)
B3=30; %(Nsec/m)
K1=015; %(N/m)
K2=015; %(N/m)
dXdt(1,1)=X(2);
dXdt(2,1)=Fa/M1-(K1/M1)*X(1)-(B1/M1)*X(2) -(B3/M1)*X(2)+(B3/M1)*X(4);
dXdt(3,1)=X(4);
dXdt(4,1)= (B3/M2)*X(2)-(B3/M2)*X(4)-(K2/M2)*X(3)-(B2/M2)*X(4);
2. Write an other M. file to call the function:
clear all
close all
clc

X0=[0;0;0;0;]; % (Initial Vb, xb, Va, xa)

[t,X]=ode45(‘multiple_element_sys ',[0 200],X0);

figure;
subplot(2,1,1);

plot(t,X(:,1));

plot(t,X(:,2),'r');
xlabel('Time(t)');
ylabel('Position xa / Speed Va');
title('Mass spring system');
legend(‘xa',‘va');
grid;
subplot(2,1,2)

plot(t,X(:,3));

hold;

plot(t,X(:,4),'r');

xlabel('Time(t)');

ylabel('Position xb / Speed Vb');

title('Mass spring system');

legend(‘xb',‘vb');

grid;
FEEDBACK CONTROL SYSTEM

LAB # 4

Prepared By :
M. Hammad Saleem

NED University of Engineering & Technology


 The objective of this session is:

o Mathematical modeling of Electrical System


Derive a mathematical model for
Series RCL Circuit

Where;

o e is applied Potential.
o i is the mesh current.
Exercise 1:

Write the differential equations for the given fig.(a)

o according to Mesh Analysis:

e(t)=VL+VC+VR

𝟏
e(t)=LD i + 𝒊+ iR
𝑪𝑫
Exercise 2:
Obtain the state equations for the given fig.(a)

o This circuit contains two energy-storage elements,


• Inductor and
• capacitor.

Let state variables are;

X1= Vc (the voltage across the capacitor) and


X2= i (the current in the inductor).

STATE EQUATION:
 The ode45 solver can be now be used:
1. create a MATLAB-function RLC.m
function dXdt=RLC(t,X)

e=60; % (V)
R=10; % (Ohm)
L=1; % (H)
C=10; % (F)

%dX/dt

dXdt(1,1)=(1/C)*X(2);
dXdt(2,1)=(-1/L)*X(1)-(R/L)*X(2)+(1/L)*e;
2. Write an other M. file to call the function:
clear
close
Clc

X0=[0 0];
[t,X]=ode45('RLC',[0 500],X0);

subplot(2,1,1);
plot(t,X(:,1));
legend('Vc');
grid on;
title('Vc');

subplot(2,1,2);
plot(t,X(:,2),'r');
legend('i');
grid on;
title('i');
Graph:
 Time constant = RC = 10*10= 100 sec
For first time constant :
 Vc=63.2% * e = 0.632*60 =37.92 V
Exercise 2:
Obtain the state equations for the given fig.(a)

Let state variables are;

X1= i1 , X2= i2 and X2= Vc

STATE EQUATION:
FEEDBACK CONTROL SYSTEM

LAB # 5

Prepared By :
Muhammad
Hammad Saleem
NED University of Engineering & Technology
 Lab Experiment 5

o Modeling of Physical Systems using


SIMULINK
 The objective of this session is:

o To use graphical user interface diagrams


to model the physical systems for the
purpose of design and analysis of control
systems.
o We will learn how MATLAB/SIMULINK
helps in solving such models.
 Overview:

o This lab introduces powerful graphical user interface (GUI),


Simulink of MATLAB.
o This software is used for solving the modeling equations
and obtaining the response of a system to different inputs.
o Both linear and nonlinear differential equations can be
solved numerically with high precision and speed, allowing
system responses to be calculated and displayed for many
input functions.
o A block diagram is an interconnection of blocks
representing basic mathematical operations in such a way
that the overall diagram is equivalent to the system’s
mathematical model.
o The lines interconnecting the blocks represent the
variables describing the system behavior.
 SIMULINK

Simulink provides access to an extensive set of blocks that accomplish a


wide range of functions useful for the simulation and analysis of dynamic
systems. The blocks are grouped into libraries, by general classes of
functions.
o Mathematical functions such as summers and gains are in the Math
library.
o Integrators are in the Continuous library.
o Constants, common input functions, and clock can all be found in the
Sources library.
o Simulink uses blocks to write a program.
o Blocks are arranged in various libraries according to their functions.
o Properties of the blocks and the values can be changed in the associated
dialog boxes.
o Some of the blocks are given below.

 SUM (Math library)

o The sum block can be represented in two ways in Simulink, by a circle


or by a rectangle.
 GAIN (Math library)

o A gain block is shown by a triangular symbol, with the gain


expression written inside

 INTEGRATOR (Continuous library)

o The block for an integrator as shown below looks unusual. The


quantity 1/s comes from the Laplace transform expression for
integration.
 CONSTANTS (Source library)

o Constants are created by the Constant block .


o Double- clicking on the symbol opens a dialog box to establish the constant’s
value.
o It can be a number or an algebraic expression using constants whose values
are defined in the workspace .

 STEP (Source library)

o A Simulink block is provided for a Step input, a signal that changes (usually
from zero) to a specified new, constant level at a specified time. These levels
and time can be specified through the dialog box, obtained by double-clicking
on the Step block.
 SIGNAL GENERATOR (Source library)

o One source of repetitive signals in Simulink is called the Signal Generator.


o Double-clicking on the Signal Generator block opens a dialog box,
o where a sine wave, a square wave, a ramp (saw tooth), or a random
waveform can be chosen.
o In addition, the amplitude and frequency of the signal may be specified.
o The signals produced have a mean value of zero.
o The repetition frequency can be given in Hertz (Hz).
 SCOPE (Sinks library)

o The system response can be examined graphically, as the simulation runs,


using the Scope block in the sinks library .
o This name is derived from the electronic instrument, oscilloscope
o which performs a similar function with electronic signals.
o Any of the variables in a Simulink diagram can be connected to the Scope
block, and when the simulation is started, that variable is displayed.
o It is possible to include several Scope blocks.
o Also it is possible to display several signals in the same scope block using
a MUX block in the signals & systems library.
o The Scope normally chooses its scales automatically to best display the
data.
 GENERAL INSTRUCTIONS FOR WRITING A SIMULINK PROGRAM

o To create a simulation in Simulink, follow the steps:

• Start MATLAB.
• Start Simulink.
• Open the libraries that contain the blocks you will need.
These usually will include the Sources, Sinks, Math and
Continuous libraries, and possibly others.
• Open a new Simulink window.
• Drag the needed blocks from their library folders to that
window. The Math library, for example, contains the Gain
and Sum blocks.
• Arrange these blocks in an orderly way corresponding to
the equations to be solved.
• Interconnect the blocks by dragging the cursor from the
output of one block to the input of another block.
Interconnecting branches can be made by right-clicking
on an existing branch.
• Double-click on any block having parameters that must
be established, and set these parameters. For
example, the gain of all Gain blocks must be set. The
number and signs of the inputs to a Sum block must be
established. The parameters of any source blocks
should also be set in this way.
• It is necessary to specify a stop time for the solution.
This is done by clicking on the Simulation >
Parameters entry on the Simulink toolbar.
Mass-Spring System Model
 Consider the Mass-Spring system used in the previous exercise as shown
in the figure.

Where;
o Fs(x) is the spring force.
o Ff(t) is the friction coefficient
o x(t) is the displacement
o Fa(t) is the applied force
 M-file for parameter values

Fa = 300; %N
M = 750; %kg
K = 15; %N/m
B = 30; % Ns/m
FEEDBACK CONTROL SYSTEM

LAB # 6

Prepared By :
Muhammad
Hammad Saleem
NED University of Engineering & Technology
 Lab Experiment 6

o we will learn how to develop a linear model


for a DC motor,
Modeling a DC Motor
 Consider a DC motor, whose electric circuit of the armature and the free
body diagram of the rotor are shown in Figure.

o Consider the following values for the physical parameters:


 Exercise 1:

o The input is the armature voltage V (ea) in Volts (driven by


a voltage source).
o Measured variables are the angular
• velocity of the shaft w in radians per second, and
• the shaft angle Q in radians.
 we can write the following equations based on the
Newton’s law combined with the Kirchhoff’s law:
 Transfer Function

o The transfer function from the input voltage, V(s), to the


output angle, Q, directly follows:

o And the transfer function from the input voltage,V(s), to the


output velocity of the shaft w in radians per second, is:
 SIMULINK Model
J = 0.01 %kg m2
b = 0.1 %Nms
K = 0.01 %Nm/A
R = 1 %ohm
L = 0.5 %H
Graph:
Lab Exercise:

o Change the electrical parameters such as


R or L to reduce the Time Constant of
motor.
FEEDBACK CONTROL SYSTEM

LAB # 9

Prepared By :
Muhammad Hammad
Saleem

NED University of Engineering & Technology


 Lab Experiment 9

(a) Response Of Control System to Ramp and Arbitrary Inputs


 Example 1:

Obtain the ramp response of the following transfer


function.
30
s 2 + 5s + 6

o There is no ramp command in MATLAB.


o However, ramp signal is one order higher than step
signal;
o the step input signal can be used to obtain the ramp
response by dividing the transfer function by s and
then evaluating it using the step command.
 The following program can be used:

close all;
clear all;
clc;
n=[0 0 30];
d=[1 5 6];
% the ramp response can be obtained by using step
command for transfer
% function divided by s.The transfer function
G1(s)=G(s)/s.
n1=[0 0 0 30];
d1=[1 5 6 0];
[y,x,t]=step(n1,d1);
% To plot output y vs time t and t vs t i.e ramp signal on
same graph window.
v=[0 10 0 10];
plot(t,y);
axis(v);
grid;
title('Plot of unit ramp response of G(s)=[30]/[s^2+5s+6]');
xlabel('Time');
ylabel('Amplitude');
 Example 2:

A closed-loop control system has a transfer function


.
𝐶(𝑠) 𝑠+5
= 3 2
𝑅(𝑠) 𝑠 +2𝑠 +3𝑠+5

 Obtain the response of the system for an input r


(t) =e^-0.2t,
for t=0 to 9 sec, in steps of 0.15 sec.
o In case the input signal is not a standard signal,
o MATLAB command lsim can be used to obtain the
response of the system.
o The syntax of the command is

lsim(n,d,u,t)

Where;
o n and d are numerator and denominator polynomials of system
transfer function.
o u is the arbitrary input signal and t defines time for which response of
the system is required.

Another form of this command, which gives the output y in vector form
without response plot, is;
[y,t]=lsim(n,d,u,t)
 The following program can be used:

n=[1 5];
d=[1 2 3 5];
t=0:0.15:9;
r=exp(-0.2*t);
y=lsim(n,d,r,t);
plot(t,r,'-',t,y,'o');
grid;
title('plot of the sytem for arbitrary input r(t)=e-0.2t');
xlabel('Time');
ylabel('Amplitude');
plot of the sysytem for arbitrary input r(t)=e-0.2t
1.4

1.2

0.8
Amplitude

0.6

0.4

0.2

-0.2

-0.4
0 1 2 3 4 5 6 7 8 9
Time
Exercises:

1) Obtain the ramp response of the following transfer


function.

30
s2 + 5s + 30
2) Obtain the response of the system defined in example
2 for an input
r (t) =sint+e-0.2t, for t=0 to 15 sec, in steps of 0.001 sec
and comment on the result.
FEEDBACK CONTROL SYSTEM

LAB # 10

Prepared By :
Muhammad Hammad Saleem

NED University of Engineering & Technology


 Lab Experiment 10

 Objective: Block Diagram Reduction Techniques:

 The objective of this exercise will be to learn commands in MATLAB that would

be used to reduce linear systems block diagram using series, parallel and

feedback configuration.
 Series Configuration:
o If the two blocks are connected as shown below then
the blocks are said to be in series.

o It would like multiplying two transfer functions.


o The MATLAB command for the such configuration is
“series”.
 The series command is implemented as shown below:

 Example 1:
Given the transfer functions of individual blocks generate the system transfer
function of the block combinations.
 Parallel Configuration:
o If the two blocks are connected as shown below then
the blocks are said to be in parallel.

o It would like adding two transfer functions.


o The MATLAB command for the such configuration is
“parallel”.
 The parallel command is implemented as shown below:

 Example 2:
For the previous systems defined, modify the MATLAB commands to obtain
the overall transfer function when the two blocks are in parallel
 Feedback Configuration:
o If the blocks are connected as shown below then the

blocks are said to be in feedback.

o Notice that in the feedback there is no transfer function


H(s) defined.
o Such a system is said to be a unity feedback system.
o The MATLAB command for the such configuration is

“feedback”.
 The feedback command is implemented as shown below:

o When H(s) is non-unity or specified, such a system is


said to be a non-unity feedback system as shown
below:
 Example 3:
Given a unity feedback system as shown in the figure, obtain the overall
transfer function using MATLAB:
 A non-unity feedback system is implemented in MATLAB using the
same “feedback” command as shown:

 Example 4:
Given a non-unity feedback system as shown in the figure, obtain the overall
transfer function using MATLAB:
Block Diagram Transformation Theorems
Exercises:
 For the following multi-loop feedback system, get closed loop transfer
function and the corresponding pole-zero map of the system.
Program:
close all G5=feedback(G3*G4,H1,+1);
clear all G6=feedback(G2*G5,H2/G4,-1);
clc
G7=feedback(G1*G6,H3,-1)
G1 = tf([1],[1 10]);
G2 = tf([1],[1 1]); zpk(G7)
G3 = tf([1 0 1],[1 4 4]); pzmap(G7)
G4 = tf([1 1],[1 6]); figure;
H1 = tf([1 1],[1 2]); step(G7);
H2 = 2; stepinfo(G7)
H3 = 1; figure;
Impulse(G7);
130

FEEDBACK CONTROL SYSTEM

LAB # 11

Prepared By :
Muhammad Hammad Saleem

NED University of Engineering & Technology


131

 Lab Experiment 11

 Objective: Introduction to PID controller

• Study the three term (PID) controller and its effects on the
feedback loop response.
• Investigate the characteristics of the each of proportional
(P), the integral (I), and the derivative (D) controls, and
• how to use them to obtain a desired response.
132

 Introduction:
o Consider the following unity feedback system:

o Plant: A system to be controlled.


o Controller: Provides excitation for the plant; Designed
to control the overall system behavior.
133

o The three-term controller: The transfer function of


the PID controller looks like the following:

o KP = Proportional gain
o KI = Integral gain
o KD = Derivative gain
134

o First, let's take a look at how the PID controller works


in a closed-loop system using the schematic shown.

o The variable (e) represents the tracking error, the


difference between the desired input value (R) and
the actual output (Y).
o This error signal (e) will be sent to the PID controller,
and
135

o The signal (u) just past the controller is now equal to


the proportional gain (KP) times the magnitude of
the error plus the integral gain (KI) times the
integral of the error plus the derivative gain (KD)
times the derivative of the error.
136

o This signal (u) will be sent to the plant, and the new
output (Y) will be obtained.
o This new output (Y) will be sent back to the sensor
again to find the new error signal (e).
o The controller takes this new error signal and
computes its derivatives and its internal again.
o The process goes on and on.
137

 Example Problem:

o Suppose we have a simple mass, spring, and damper


problem .

o The transfer function between the displacement X(s)


and the input F(s) then becomes:
138

Let
 M = 1kg
 b = 10 N.s/m
 k = 20 N/m
 F(s) = 1

o Plug these values into the above transfer function

o The goal of this problem is to show you how each of


Kp, Ki and Kd contributes to obtain
 Fast rise time
 Minimum overshoot
 No steady-state error
139

 Open-loop step response:


Let's first view the open-loop step response.

num=1;
den=[1 10 20];
plant=tf(num,den);
step(plant)

MATLAB command window should give you the


plot shown below.
140
141

o 0.05 is the final value of the output to a unit step input.


o This corresponds to the steady-state error of 0.95,
quite large indeed.
o Furthermore, the rise time is about one second, and
the settling time is about 1.5 seconds.
o Let's design a controller that will reduce the rise
time, reduce the settling time, and eliminates the
steady-state error.
142

 Proportional control:
o The closed-loop transfer function of the above system
with a proportional controller is:

o Let the proportional gain (KP) equal 300:


143

 Proportional control:
Kp=300;
contr=Kp;
sys_cl=feedback(contr*plant,1); %by default –ve
feedback
t=0:0.01:2;
step(sys_cl,t)
144

Proportional control:

• reduced both the rise time and the


steady-state error,
• increased the overshoot, and
• decreased the settling time by small
amount.
145

 Proportional-Derivative control:
o The closed-loop transfer function of the given system with
a PD controller is:

o Let KP equal 300 as before and let KD equal 10.


146

 Proportional-Derivative control:

Kp=300;
Kd=10;
contr=tf([Kd Kp],1);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
147

Proportional-Derivative control:

• reduced both the overshoot and the


settling time, and
• had a small effect on the rise time and
the steady-state error
148

 Proportional-Integral control:
o The closed-loop transfer function of the given system with
a PI controller is:

o Let KP equal 30 and let KI equal 70.


149

 Proportional-Integral control:

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)
150

Proportional-Integral control:

• reduces the rise time and


• increases the overshoot as the
proportional controller does
• integral controller eliminated the steady-
state error.
151

 Proportional-Integral-Derivative control:
o Now, let's take a look at a PID controller. The closed-loop
transfer function of the given system with a PID controller
is:

o After several trial and error runs, the gains Kp=350,


Ki=300, and Kd=50 provided the desired response.
152

 Proportional-Integral-Derivative control:
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)
153

Proportional-Integral-Derivative control

• no overshoot,
• fast rise time, and
• no steady-state error.
154

 The characteristics of P, I, and D controllers:

o The proportional controller (KP) will have the


effect of reducing the rise time and will reduce,
but never eliminate, the steady state error.
o An integral controller (KI) will have the effect of
eliminating the steady state error, but it may
make the transient response worse.
o A derivative control (KD) will have the effect of
increasing the stability of the system, reducing
the overshoot and improving the transient
response.
155

o Effect of each controller KP, KI and KD on the closed-loop


system are summarized below:
156

Exercise:

Vous aimerez peut-être aussi