Delft: Matlab and Simulink For Modeling and Control
Delft: Matlab and Simulink For Modeling and Control
November 1999
Delft
Delft University of Technology
Control Laboratory
Faculty of Information Technology and Systems
Delft University of Technology
P.O. Box 5031, 2600 GA Delft, The Netherlands
1 Introduction
With the help of two examples, a DC motor and a magnetic levitation system, the use of M ATLAB and
Simulink for modeling, analysis and control design is demonstrated. It is assumed that the reader already
has basic knowledge of M ATLAB and Simulink. The main focus is on the use of the Control System Toolbox
functions. We recommend the reader to try the commands out directly in M ATLAB while reading this text. The
examples have been implemented by the authors and can be downloaded from http://lcewww.et.tudelft.nl/et4092.
The implementation is done in M ATLAB version 5.3 and has also been tested in version 5.2.
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.
L
+
+
V
T
J
Vb = K
-
J =0.01 kg m2
b =0.1 Nms
K =0.01 Nm/A
R=1
L = 0.5 H
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.
(1)
The back electromotive force (emf), Vb , is related to the angular velocity by:
Vb = K = K
1
d
.
dt
(2)
From Figure 1 we can write the following equations based on the Newtons law combined with the Kirchhoffs
law:
d2
d
+b
= Ki,
2
dt
dt
di
d
L + Ri = V K .
dt
dt
(3)
(4)
(5)
(6)
where s denotes the Laplace operator. From (6) we can express I(s):
I(s) =
V (s) Ks(s)
,
R + Ls
(7)
V (s) Ks(s)
.
R + Ls
(8)
This equation for the DC motor is shown in the block diagram in Figure 2.
Armature
Voltage
V(s) +
-
Load
Torque
T(s)
Ls + R
Vb(s)
Back emf
Velocity
w( ) s
Js + b
Angle
q( ) s
(s)
K
=
.
V (s)
s[(R + Ls)(Js + b) + K 2 ]
(9)
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:
(s)
K
Gv (s) =
.
(10)
=
V (s)
(R + Ls)(Js + b) + K 2
3 MATLAB Representation
The above transfer function can be entered into Matlab by defining the numerator and denominator polynomials, using the conventions of the MATLABs Control Toolbox. The coefficients of a polynomial in s are
2
=
=
=
=
Voltage;
Velocity;
Voltage;
Angle;
Now by calling motor from the workspace, we have both the velocity (Gv) and the position (Ga) transfer
functions defined in the workspace.
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?
3. How can you use M ATLAB to find out whether the system is observable and controllable?
3
4 Analysis
The Control System Toolbox offers a variety of functions that allow us to examine the systems characteristics.
Impulse Response
From: Voltage
From: Voltage
0.1
0.2
0.15
To: Velocity
To: Velocity
0.08
0.06
0.04
0.05
Amplitude
Amplitude
0.02
0
0.25
0
0.1
0.2
0.08
0.15
0.06
To: Angle
To: Angle
0.1
0.1
0.05
0
0.04
0.02
0.5
1.5
2.5
0.5
Time (sec.)
1.5
2.5
Time (sec.)
4.2 Exercise
1. Simulate and plot in M ATLAB the time response of the velocity and of the angle for an input signal
cos 2t, where t goes from 0 to 5 seconds.
4
Bode Diagrams
From: Voltage
50
To: Velocity
100
0
100
200
200
To: Angle
200
0
200
400
2
10
10
10
10
10
Frequency (rad/sec)
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:
C(s) =
U (s)
Ki
Kd s2 + Kp s + Ki
= Kp +
+ Kd s =
,
E(s)
s
s
(11)
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.
r +
Velocity
Voltage
PID
DC Motor
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:
Step Response
From: Desired velocity
1.4
1.2
Amplitude
To: Velocity
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
Time (sec.)
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.
6
Step Response
1.4
1.2
To: Angle
Amplitude
0.8
0.6
0.4
0.2
0.5
1.5
2.5
3.5
4.5
Time (sec.)
6 SIMULINK Model
The block diagram from Figure 2 can be directly implemented in SIMULINK, as shown in the figure Figure 8:
Step Input
+
Armature
Load
K(s)
Ls+R
1
Js+b
1
s
angle
theta
To Workspace
angular
speed
omega
t
Clock
To Workspace
To Workspace
Step Input
+
PID
DC motor
angular
speed
Sum
omega
To Workspace
t
Clock
To Workspace
1
Inport
Armature
Load
K(s)
Ls+R
1
Js+b
1
s
1
Outport
Figure 10: SIMULINK block diagram of the DC motor with Inport and Outport blocks.
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 M ATLAB.
FR
A-D
Airgap
z
Computer
D-A
Current i
Fgrav Fdist
dynamic equation of the system is derived from the basic law F = ma,
d2
1
y(t) = (Fgrav + Fdist FR ),
2
dt
m
(12)
where Fgrav = mg, Fdist is an unknown disturbance, and the electromagnetic force is
FR =
i2 (t)
0 N 2 Ai2 (t)
= Kmag 2 .
2
2y (t)
y (t)
(13)
1
Current
2
Disturbance
force
u2
Kmag/m
y
1/m
y
1
1
Air gap
Check limits
Figure 12: Nonlinear Simulink model (bearing.mdl) of the magnetic levitation system.
8.3 Linearization
Let us linearize the nonlinear model around an operating point y0 = 2 mm. There are two possibilities to
linearize a nonlinear model:
Analytically: by hand or using symbolic maths software such as Mathematica, Maple or the Symbolic
Toolbox of M ATLAB.
Numerically by applying the trim and linmod functions of M ATLAB.
The second possibility will be explored here (you can do the first one as an exercise). Let us use the following
script (lin.m):
params;
% a script with definition of systems parameters
file = bearing;
% nonlinear Simulink model to be linearized
u0 = [10; 0];
% initial input guess
[input; disturbance]
y0 = 0.002;
% initial output guess
x0 = [y0 0];
% initial state guess
[x0,u0]=trim(file,x0,u0,y0,[],[2],[]);
[A,B,C,D] = linmod(file,x0,u0);
sys = ss(A,B,C,D);
% make an LTI object
9
The trim function numerically searches for an equilibrium of the nonlinear system. A reasonable initial guess
(x0, u0 and y0) must be provided. The additional parameters of this function are indices of the inputs, states
and outputs that are not free to vary during the search. A typical example of such a variable is the state variable
corresponding to the operating point.
The linmod function extracts the matrices of a linear model obtained by numerical linearization at the equilibrium. Once this model is available, it can be used for analysis or control design.
8.4 Exercise
1. Choose another operating point and extract a linear model at that point. Compare to the model obtained
above in terms their gains, poles and zeros.
9 Concluding Remarks
The authors hope that this text has been useful and would appreciate receiving feedback from you. Let us
know if you have found any errors and omissions or if you have suggestions for improvements. Send them
preferable by e-mail to: [email protected].
10