SlideShare a Scribd company logo
Modeling and Control
with
Matlab and Simulink
Sch. of Elec. Eng., Wuhan Univ.
June 2003
Spring 2003
Modeling and Control with Matlab and Simulink 2
1. Introduction
With the help of an example, a DC motor,
the use of MATLAB and Simulink for modeling,
analysis and control design is demonstrated.
It is assumed that the reader already has
basic knowledge of MATLAB and Simulink.
The main focus is on the use of the Control
System Toolbox functions.
Spring 2003
Modeling and Control with Matlab and Simulink 3
2. Modeling a DC Motor
In this example we will learn how to
develop a linear model for a DC motor,
how to analyze the model under MATLAB
(poles and zeros, frequency response,
time-domain response, etc.), how to
design a controller, and how to simulate
the open-loop and closed-loop systems
under SIMULINK.
Spring 2003
Modeling and Control with Matlab and Simulink 4
2.1 Physical System
Consider a DC motor, whose electric circuit of the armature
and the free body diagram of the rotor are shown in Figure
1.
Spring 2003
Modeling and Control with Matlab and Simulink 5
Physical System
The rotor and the shaft are assumed to be rigid. Consider the
following values for the physical parameters:
moment of inertia of the rotor J = 0.01 kg  m2
damping (friction) of the mechanical
system
b = 0.1 Nms
(back-)electromotive force constant K = 0.01 Nm/A
electric resistance R = 1 
electric inductance L = 0.5 H
Spring 2003
Modeling and Control with Matlab and Simulink 6
Physical System
The input is the armature voltage V in Volts (driven by a
voltage source). Measured variables are the angular
velocity of the shaft  in radians per second, and the shaft
angle  in radians.
Spring 2003
Modeling and Control with Matlab and Simulink 7
System Equations
The motor torque, T, is related to the armature current, i,
by a constant factor K:
(1)
The back electromotive force (emf), Vb, is related to the
angular velocity by:
(2)
Spring 2003
Modeling and Control with Matlab and Simulink 8
2.3 Transfer Function
From Figure 1 we can write the following equations based on
the Newtons law combined with the Kirchhoffs law:
Using the Laplace transform, equations (3) and (4) can be
written as:
Spring 2003
Modeling and Control with Matlab and Simulink 9
Transfer Function
where s denotes the Laplace operator. From (6) we can
express I(s):
and substitute it in (5) to obtain:
Spring 2003
Modeling and Control with Matlab and Simulink 10
Transfer Function
This equation for the DC motor is shown in the block diagram
in Figure 2.
Spring 2003
Modeling and Control with Matlab and Simulink 11
Transfer Function
From equation (8), the transfer function from the input voltage,
V (s), to the output angle,  , directly follows:
From the block diagram in Figure 2, it is easy to see that the
transfer function from the input voltage, V (s), to
the angular velocity, , is:
Spring 2003
Modeling and Control with Matlab and Simulink 12
3 MATLAB Representation
The above transfer function can be entered into Matlab by
defining the numerator and denominator polynomials, using
the conventions of the MATLAB's Control Toolbox. The
coefficients of a polynomial in s are entered in a descending
order of the powers of s.
Example: The polynomial A = 3s3
+ 2s + 10 is in MATLAB
entered as: A = [3 0 2 10].
Furthermore, we will make use of the function conv(A,B),
which computes the product (convolution) of the polynomials A
and B. Open the M-file motor.m. It already contains the
definition of the motor constants:
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
Spring 2003
Modeling and Control with Matlab and Simulink 13
MATLAB Representation
The transfer function (9) can be entered in MATLAB in a
number of different ways.
1. As Ga(s) can be expressed as Gv(s)  1/s, we can enter
these two transfer functions separately and combine them
in series:
aux = tf(K,conv([L, R],[J, b]));
Gv = feedback(aux,K);
Ga = tf(1,[1, 0])*Gv;
Here, we made use of the function feedback to create a
feedback connection of two transfer functions and the
multiplication operator *, which is overloaded by the LTI
class of the Control System Toolbox such that is computes
the product of two transfer functions.
Spring 2003
Modeling and Control with Matlab and Simulink 14
MATLAB Representation
2. Instead of using convolution, the first of the above three
commands can be replaced by the product of
two transfer functions:
aux = tf(K,[L, R]) * tf(1,[J, b]);
3. Another possibility (perhaps the most convenient one) is to
define the transfer function in a symbolic way. First introduce a
system representing the Laplace operator s (differentiator) and
then enter the transfer function as an algebraic expression:
s = tf([1, 0],1);
Gv = K/((L*s + R)*(J*s + b) + K^2);
Ga = Gv/s;
Spring 2003
Modeling and Control with Matlab and Simulink 15
MATLAB Representation
It is convenient to label the inputs and outputs by the names
of the physical variables they represent:
Gv.InputName = 'Voltage';
Gv.OutputName = 'Velocity';
Ga.InputName = 'Voltage';
Ga.OutputName = 'Angle';
Now by calling motor from the workspace, we have both the
velocity (Gv) and the position (Ga) transfer functions defined
in the workspace.
Spring 2003
Modeling and Control with Matlab and Simulink 16
3.1 Exercises
1. Convert Gv and Ga into their respective state-
space (function ss) and zero-pole-gain (function
zpk) representations.
2. What are the poles and zeros of the system? Is
the system stable? Why?
Spring 2003
Modeling and Control with Matlab and Simulink 17
4 Analysis
The Control System Toolbox offers a variety of functions that allow
us to examine the systems characteristics.
4.1 Time-Domain and Frequency Responses
As we may want plot the responses for the velocity and angle in
one figure, it convenient to group the two
transfer functions into a single system with one input, the voltage,
and two outputs, the velocity and the angle:
G = [Gv; Ga];
Spring 2003
Modeling and Control with Matlab and Simulink 18
Analysis
Another way is to first convert Ga into its state-space
representation and then add one extra output being equal to
the second state (the velocity):
G = ss(Ga);
set(G,'c',[0 1 0; 0 0 1], …
'd',[0;0], 'OutputName',{'Velocity'; 'Angle'});
Note that this extension of the state-space model with an
extra output has to be done in one set command in order to
keep the dimensions consistent.
Spring 2003
Modeling and Control with Matlab and Simulink 19
Analysis
Now, we can plot the step, impulse and frequency responses
of the motor model:
figure(1); step(G);
figure(2); impulse(G);
figure(3); bode(G);
You should get the plots given in Figure 3 and Figure 4.
Spring 2003
Modeling and Control with Matlab and Simulink 20
Analysis
Spring 2003
Modeling and Control with Matlab and Simulink 21
Analysis
Spring 2003
Modeling and Control with Matlab and Simulink 22
4.2 Exercise
1. Simulate and plot in MATLAB the time response of the
velocity and of the angle for an input signal cos(2t), where t
goes from 0 to 5 seconds.
Spring 2003
Modeling and Control with Matlab and Simulink 23
5 Control Design
Let us design a PID feedback controller to control the velocity
of the DC motor. Recall that the transfer function of a PID
controller is:
Spring 2003
Modeling and Control with Matlab and Simulink 24
5 Control Design
where u is the controller output (in our case the voltage V ),
e = uc - y is the controller input (the control error), and Kp, Kd, Ki
are the proportional, derivative and integral gains, respectively.
A block diagram of the closed-loop system is given in Figure 5.
Spring 2003
Modeling and Control with Matlab and Simulink 25
5.1 Proportional Control
First, try a simple proportional controller with some estimated
gain, say, 100. To compute the closed-loop
transfer function, use the feedback command. Add the
following lines to your m-file:
Kp = 100;
Gc = feedback(Gv*Kp,1);
Gc.InputName = 'Desired velocity';
Here Gc is the closed-loop transfer function. To see the
step response of the closed-loop system, enter:
figure(4); step(Gc,0:0.01:2);
You should get the plot given in Figure 6:
Spring 2003
Modeling and Control with Matlab and Simulink 26
To eliminate the steady-state error, an integral action must be
used. To reduce the overshoot, a derivative action can be
employed. In the following section, a complete PID controller
is designed.
5 Proportional Control
To eliminate the steady-state error, an integral action must be
used. To reduce the overshoot, a derivative action can be
employed. In the following section, a complete PID controller
is designed.
Spring 2003
Modeling and Control with Matlab and Simulink 27
5.2 PID Control
Let us try a PID controller. Edit your M-file so that it contains
the following commands:
Kp = 1;
Ki = 0.8;
Kd = 0.3;
C = tf([Kd Kp Ki],[1 0]);
rlocus(Ga*C);
Kp = rlocfind(Ga*C);
Gc = feedback(Ga*C*Kp,1);
figure(9); step(Gc,0:0.01:5)
The rlocus and rlocfind functions are used to select the overall
gain of the PID controller, such that the controller is stable and
has the desired location of the poles (within the defined ratio
among the Kp, Ki and Kd constants). If the design is not
satisfactory, this ratio can be changed, of course. We should
obtain a plot similar to the one in Figure 7:
Spring 2003
Modeling and Control with Matlab and Simulink 28
PID Control
Spring 2003
Modeling and Control with Matlab and Simulink 29
5.3 Exercise
1. Use the root locus and the Nyquist criterion to find out for
what value of the gain Kp the proportional controller for the
angle Ga(s) becomes unstable.
Spring 2003
Modeling and Control with Matlab and Simulink 30
6 SIMULINK Model
The block diagram from Figure 2 can be directly
implemented in SIMULINK, as shown in the figure Figure 8:
Spring 2003
Modeling and Control with Matlab and Simulink 31
SIMULINK Model
Set the simulation parameters and run the simulation to see the
step response. Compare with the response in Figure 3. Save
the file under a new name and remove the position integrator
along with the Graph and To Workspace blocks. Group the
block describing the DC motor into a single block and add a
PID controller according to Figure 5. The corresponding
SIMULINK diagram is given in Figure 9. Experiment with the
controller. Compare the responses with those obtained
previously in MATLAB.
Spring 2003
Modeling and Control with Matlab and Simulink 32
7 Obtaining MATLAB Representation from a SIMULINK Model
From a SIMULINK diagram, a MATLAB representation (state
space, transfer function, etc.) can be obtained.
The Inport and Outport blocks must be added to the
SIMULINK diagram, as shown in Figure 10.
Then we can use the linmod command to obtain a state-space
representation of the diagram:
[A,B,C,D] = linmod(filename);
where filename is the name of the SIMULINK file.
Spring 2003
Modeling and Control with Matlab and Simulink 33
Obtaining MATLAB Representation from a SIMULINK Model
Spring 2003
Modeling and Control with Matlab and Simulink 34
7.1 Exercise
1. Convert the four matrices A, B, C, and D into a
corresponding state space LTI object. Convert this one into a
transfer function and compare the result with the transfer
function entered previously in MATLAB.

More Related Content

PDF
Raymond.Brunkow-Project-EEL-3657-Sp15
DOC
493 297
PDF
Modeling, simulation and control of a robotic arm
PDF
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
PDF
Optimal and pid controller for controlling camera’s position in unmanned aeri...
PDF
Small Signal Modelling and Controller Design of Boost Converter using MATLAB
PDF
PID Tuning using Ziegler Nicholas - MATLAB Approach
DOCX
Suspension system modeling buss
Raymond.Brunkow-Project-EEL-3657-Sp15
493 297
Modeling, simulation and control of a robotic arm
Optimal and Pid Controller for Controlling Camera's Position InUnmanned Aeria...
Optimal and pid controller for controlling camera’s position in unmanned aeri...
Small Signal Modelling and Controller Design of Boost Converter using MATLAB
PID Tuning using Ziegler Nicholas - MATLAB Approach
Suspension system modeling buss

Similar to Matlab And Simulink For Modeling And Control.ppt (20)

PDF
DC Motor Modelling & Design Fullstate Feedback Controller
PDF
Control tutorials for matlab and simulink introduction pid controller desig...
PDF
Iaetsd modelling of one link flexible arm manipulator using
PDF
Ball and beam
PDF
Linear Control Hard-Disk Read/Write Controller Assignment
DOC
Basic Control System unit6
PDF
CE150--Hongyi Huang
PDF
Control of Wind Energy Conversion System and Power Quality Improvement in the...
PDF
SIMMECHANICS VISUALIZATION OF EXPERIMENTAL MODEL OVERHEAD CRANE, ITS LINEARIZ...
PDF
matlab_simulink_for_control082p.pdf
PDF
SIMMECHANICS VISUALIZATION OF EXPERIMENTAL MODEL OVERHEAD CRANE,ITS LINEARIZA...
PDF
2313ijccms01.pdf
PDF
2313ijccms01.pdf
PPTX
TRANSFER FUNCTION (4).pptx
PDF
Modeling and simulation of vehicle windshield wiper system using h infinity l...
PDF
Modular Approach to Implement Model Predictive Control on Three Phase Voltage...
PDF
AntennaProject_NathanJaniczek
DOCX
Ece 415 control systems, fall 2021 computer project 1
PDF
control system lab 02 - PID tuning
PDF
Design and control of ems magnetic levitation train using fuzzy mras and pid ...
DC Motor Modelling & Design Fullstate Feedback Controller
Control tutorials for matlab and simulink introduction pid controller desig...
Iaetsd modelling of one link flexible arm manipulator using
Ball and beam
Linear Control Hard-Disk Read/Write Controller Assignment
Basic Control System unit6
CE150--Hongyi Huang
Control of Wind Energy Conversion System and Power Quality Improvement in the...
SIMMECHANICS VISUALIZATION OF EXPERIMENTAL MODEL OVERHEAD CRANE, ITS LINEARIZ...
matlab_simulink_for_control082p.pdf
SIMMECHANICS VISUALIZATION OF EXPERIMENTAL MODEL OVERHEAD CRANE,ITS LINEARIZA...
2313ijccms01.pdf
2313ijccms01.pdf
TRANSFER FUNCTION (4).pptx
Modeling and simulation of vehicle windshield wiper system using h infinity l...
Modular Approach to Implement Model Predictive Control on Three Phase Voltage...
AntennaProject_NathanJaniczek
Ece 415 control systems, fall 2021 computer project 1
control system lab 02 - PID tuning
Design and control of ems magnetic levitation train using fuzzy mras and pid ...
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
R24 SURVEYING LAB MANUAL for civil enggi
DOCX
573137875-Attendance-Management-System-original
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPT
Project quality management in manufacturing
PPTX
Sustainable Sites - Green Building Construction
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Welding lecture in detail for understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
OOP with Java - Java Introduction (Basics)
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
R24 SURVEYING LAB MANUAL for civil enggi
573137875-Attendance-Management-System-original
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Lecture Notes Electrical Wiring System Components
Project quality management in manufacturing
Sustainable Sites - Green Building Construction
Operating System & Kernel Study Guide-1 - converted.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
bas. eng. economics group 4 presentation 1.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
UNIT 4 Total Quality Management .pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Internet of Things (IOT) - A guide to understanding
Welding lecture in detail for understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Ad

Matlab And Simulink For Modeling And Control.ppt

  • 1. Modeling and Control with Matlab and Simulink Sch. of Elec. Eng., Wuhan Univ. June 2003
  • 2. Spring 2003 Modeling and Control with Matlab and Simulink 2 1. Introduction With the help of an example, a DC motor, the use of MATLAB and Simulink for modeling, analysis and control design is demonstrated. It is assumed that the reader already has basic knowledge of MATLAB and Simulink. The main focus is on the use of the Control System Toolbox functions.
  • 3. Spring 2003 Modeling and Control with Matlab and Simulink 3 2. Modeling a DC Motor In this example we will learn how to develop a linear model for a DC motor, how to analyze the model under MATLAB (poles and zeros, frequency response, time-domain response, etc.), how to design a controller, and how to simulate the open-loop and closed-loop systems under SIMULINK.
  • 4. Spring 2003 Modeling and Control with Matlab and Simulink 4 2.1 Physical System Consider a DC motor, whose electric circuit of the armature and the free body diagram of the rotor are shown in Figure 1.
  • 5. Spring 2003 Modeling and Control with Matlab and Simulink 5 Physical System The rotor and the shaft are assumed to be rigid. Consider the following values for the physical parameters: moment of inertia of the rotor J = 0.01 kg  m2 damping (friction) of the mechanical system b = 0.1 Nms (back-)electromotive force constant K = 0.01 Nm/A electric resistance R = 1  electric inductance L = 0.5 H
  • 6. Spring 2003 Modeling and Control with Matlab and Simulink 6 Physical System The input is the armature voltage V in Volts (driven by a voltage source). Measured variables are the angular velocity of the shaft  in radians per second, and the shaft angle  in radians.
  • 7. Spring 2003 Modeling and Control with Matlab and Simulink 7 System Equations The motor torque, T, is related to the armature current, i, by a constant factor K: (1) The back electromotive force (emf), Vb, is related to the angular velocity by: (2)
  • 8. Spring 2003 Modeling and Control with Matlab and Simulink 8 2.3 Transfer Function From Figure 1 we can write the following equations based on the Newtons law combined with the Kirchhoffs law: Using the Laplace transform, equations (3) and (4) can be written as:
  • 9. Spring 2003 Modeling and Control with Matlab and Simulink 9 Transfer Function where s denotes the Laplace operator. From (6) we can express I(s): and substitute it in (5) to obtain:
  • 10. Spring 2003 Modeling and Control with Matlab and Simulink 10 Transfer Function This equation for the DC motor is shown in the block diagram in Figure 2.
  • 11. Spring 2003 Modeling and Control with Matlab and Simulink 11 Transfer Function From equation (8), the transfer function from the input voltage, V (s), to the output angle,  , directly follows: From the block diagram in Figure 2, it is easy to see that the transfer function from the input voltage, V (s), to the angular velocity, , is:
  • 12. Spring 2003 Modeling and Control with Matlab and Simulink 12 3 MATLAB Representation The above transfer function can be entered into Matlab by defining the numerator and denominator polynomials, using the conventions of the MATLAB's Control Toolbox. The coefficients of a polynomial in s are entered in a descending order of the powers of s. Example: The polynomial A = 3s3 + 2s + 10 is in MATLAB entered as: A = [3 0 2 10]. Furthermore, we will make use of the function conv(A,B), which computes the product (convolution) of the polynomials A and B. Open the M-file motor.m. It already contains the definition of the motor constants: J=0.01; b=0.1; K=0.01; R=1; L=0.5;
  • 13. Spring 2003 Modeling and Control with Matlab and Simulink 13 MATLAB Representation The transfer function (9) can be entered in MATLAB in a number of different ways. 1. As Ga(s) can be expressed as Gv(s)  1/s, we can enter these two transfer functions separately and combine them in series: aux = tf(K,conv([L, R],[J, b])); Gv = feedback(aux,K); Ga = tf(1,[1, 0])*Gv; Here, we made use of the function feedback to create a feedback connection of two transfer functions and the multiplication operator *, which is overloaded by the LTI class of the Control System Toolbox such that is computes the product of two transfer functions.
  • 14. Spring 2003 Modeling and Control with Matlab and Simulink 14 MATLAB Representation 2. Instead of using convolution, the first of the above three commands can be replaced by the product of two transfer functions: aux = tf(K,[L, R]) * tf(1,[J, b]); 3. Another possibility (perhaps the most convenient one) is to define the transfer function in a symbolic way. First introduce a system representing the Laplace operator s (differentiator) and then enter the transfer function as an algebraic expression: s = tf([1, 0],1); Gv = K/((L*s + R)*(J*s + b) + K^2); Ga = Gv/s;
  • 15. Spring 2003 Modeling and Control with Matlab and Simulink 15 MATLAB Representation It is convenient to label the inputs and outputs by the names of the physical variables they represent: Gv.InputName = 'Voltage'; Gv.OutputName = 'Velocity'; Ga.InputName = 'Voltage'; Ga.OutputName = 'Angle'; Now by calling motor from the workspace, we have both the velocity (Gv) and the position (Ga) transfer functions defined in the workspace.
  • 16. Spring 2003 Modeling and Control with Matlab and Simulink 16 3.1 Exercises 1. Convert Gv and Ga into their respective state- space (function ss) and zero-pole-gain (function zpk) representations. 2. What are the poles and zeros of the system? Is the system stable? Why?
  • 17. Spring 2003 Modeling and Control with Matlab and Simulink 17 4 Analysis The Control System Toolbox offers a variety of functions that allow us to examine the systems characteristics. 4.1 Time-Domain and Frequency Responses As we may want plot the responses for the velocity and angle in one figure, it convenient to group the two transfer functions into a single system with one input, the voltage, and two outputs, the velocity and the angle: G = [Gv; Ga];
  • 18. Spring 2003 Modeling and Control with Matlab and Simulink 18 Analysis Another way is to first convert Ga into its state-space representation and then add one extra output being equal to the second state (the velocity): G = ss(Ga); set(G,'c',[0 1 0; 0 0 1], … 'd',[0;0], 'OutputName',{'Velocity'; 'Angle'}); Note that this extension of the state-space model with an extra output has to be done in one set command in order to keep the dimensions consistent.
  • 19. Spring 2003 Modeling and Control with Matlab and Simulink 19 Analysis Now, we can plot the step, impulse and frequency responses of the motor model: figure(1); step(G); figure(2); impulse(G); figure(3); bode(G); You should get the plots given in Figure 3 and Figure 4.
  • 20. Spring 2003 Modeling and Control with Matlab and Simulink 20 Analysis
  • 21. Spring 2003 Modeling and Control with Matlab and Simulink 21 Analysis
  • 22. Spring 2003 Modeling and Control with Matlab and Simulink 22 4.2 Exercise 1. Simulate and plot in MATLAB the time response of the velocity and of the angle for an input signal cos(2t), where t goes from 0 to 5 seconds.
  • 23. Spring 2003 Modeling and Control with Matlab and Simulink 23 5 Control Design Let us design a PID feedback controller to control the velocity of the DC motor. Recall that the transfer function of a PID controller is:
  • 24. Spring 2003 Modeling and Control with Matlab and Simulink 24 5 Control Design where u is the controller output (in our case the voltage V ), e = uc - y is the controller input (the control error), and Kp, Kd, Ki are the proportional, derivative and integral gains, respectively. A block diagram of the closed-loop system is given in Figure 5.
  • 25. Spring 2003 Modeling and Control with Matlab and Simulink 25 5.1 Proportional Control First, try a simple proportional controller with some estimated gain, say, 100. To compute the closed-loop transfer function, use the feedback command. Add the following lines to your m-file: Kp = 100; Gc = feedback(Gv*Kp,1); Gc.InputName = 'Desired velocity'; Here Gc is the closed-loop transfer function. To see the step response of the closed-loop system, enter: figure(4); step(Gc,0:0.01:2); You should get the plot given in Figure 6:
  • 26. Spring 2003 Modeling and Control with Matlab and Simulink 26 To eliminate the steady-state error, an integral action must be used. To reduce the overshoot, a derivative action can be employed. In the following section, a complete PID controller is designed. 5 Proportional Control To eliminate the steady-state error, an integral action must be used. To reduce the overshoot, a derivative action can be employed. In the following section, a complete PID controller is designed.
  • 27. Spring 2003 Modeling and Control with Matlab and Simulink 27 5.2 PID Control Let us try a PID controller. Edit your M-file so that it contains the following commands: Kp = 1; Ki = 0.8; Kd = 0.3; C = tf([Kd Kp Ki],[1 0]); rlocus(Ga*C); Kp = rlocfind(Ga*C); Gc = feedback(Ga*C*Kp,1); figure(9); step(Gc,0:0.01:5) The rlocus and rlocfind functions are used to select the overall gain of the PID controller, such that the controller is stable and has the desired location of the poles (within the defined ratio among the Kp, Ki and Kd constants). If the design is not satisfactory, this ratio can be changed, of course. We should obtain a plot similar to the one in Figure 7:
  • 28. Spring 2003 Modeling and Control with Matlab and Simulink 28 PID Control
  • 29. Spring 2003 Modeling and Control with Matlab and Simulink 29 5.3 Exercise 1. Use the root locus and the Nyquist criterion to find out for what value of the gain Kp the proportional controller for the angle Ga(s) becomes unstable.
  • 30. Spring 2003 Modeling and Control with Matlab and Simulink 30 6 SIMULINK Model The block diagram from Figure 2 can be directly implemented in SIMULINK, as shown in the figure Figure 8:
  • 31. Spring 2003 Modeling and Control with Matlab and Simulink 31 SIMULINK Model Set the simulation parameters and run the simulation to see the step response. Compare with the response in Figure 3. Save the file under a new name and remove the position integrator along with the Graph and To Workspace blocks. Group the block describing the DC motor into a single block and add a PID controller according to Figure 5. The corresponding SIMULINK diagram is given in Figure 9. Experiment with the controller. Compare the responses with those obtained previously in MATLAB.
  • 32. Spring 2003 Modeling and Control with Matlab and Simulink 32 7 Obtaining MATLAB Representation from a SIMULINK Model From a SIMULINK diagram, a MATLAB representation (state space, transfer function, etc.) can be obtained. The Inport and Outport blocks must be added to the SIMULINK diagram, as shown in Figure 10. Then we can use the linmod command to obtain a state-space representation of the diagram: [A,B,C,D] = linmod(filename); where filename is the name of the SIMULINK file.
  • 33. Spring 2003 Modeling and Control with Matlab and Simulink 33 Obtaining MATLAB Representation from a SIMULINK Model
  • 34. Spring 2003 Modeling and Control with Matlab and Simulink 34 7.1 Exercise 1. Convert the four matrices A, B, C, and D into a corresponding state space LTI object. Convert this one into a transfer function and compare the result with the transfer function entered previously in MATLAB.