Upload
figas007
View
238
Download
0
Tags:
Embed Size (px)
DESCRIPTION
simulink
Citation preview
11
Pedro BeiroInstituto Superior de Engenharia de Coimbra
Departamento de Engenharia MecnicaRua Pedro Nunes, 3030 - 199 Coimbra, Portugal
Instrumentao e ControloMdulo de Controlo de Sistemas
2
Launching Simulink
In the MATLAB command window type>> simulink
23
Creating a new model
Click the New model iconin the upper left corner tostart a new Simulink file
Select the Simulink icon toshow elements on the file
4
Library of elements
New model is created here
Workspace
35
Saving the new model
Create a new folder (eg.: simulink_files)
Use .mdl suffix when saving
6
Example 1
Build a Simulink model to solve the differential equation
Initial condition x(0) = -1
Input function 3sin(2t)
Output solution of differential equation x(t)
=x(t) 3sin(2t)
47
Example 1
Build this model in Simulink
1s
Integrator
x(0) = -1
input3sin(2t)
outputx(t)
x(t) x(t)
8
Example 1
Drag a Sine Wave block from Sources library to themodel window
Select an input block
59
Example 1
Drag an Integrator block from Continuous library to themodel window
Select an operator block
10
Example 1
Drag a Scope block from Sinks library to the modelwindow
Select an output block
611
Example 1
Place the cursor on Sine Wave block output and dragfrom there to the Integrator input
Place the cursor on Integrator block output and drag fromthere to the Scope input
Arrows indicate the direction of signal flowConnect blocks with signals
12
Example 1
Double-click on Sine Wave block to set amplitude = 3and frequency = 2
This produces the desired input function 3sin(2t)Select simulation parameters
713
Example 1
Double-click on Integrator block to set initial condition = -1
Select simulation parameters
14
Example 1
Run the simulation in the model window select Startfrom Simulation menu
View the output x(t) in Scope window
Run the simulation
815
Example 1
Double-click on Scope block to view simulation results
Simulation results
16
Example 2
Build a Simulink model to solve the differential equation
Second order mass-spring-damper system
Initial conditions zero
Input f(t) step with magnitude 3
Parameters m = 0.25, c = 0.5, k = 1
+ + = mx(t) cx(t) kx(t) f(t)
917
Example 2
Solve for the term with highest-order derivative
Make the left-hand side of this equation the output of asumming block
= mx(t) f(t) cx(t) kx(t)
Sum
mx(t)+-
-
18
Example 2
Drag a Sum block from Math library to the model window
10
19
Example 2
Double-click to change block parameters to rectangularand + - -
20
Example 2
Add a gain (multiplier) block to eliminate the coefficient mand produce the highest-derivative alone
1m
mx(t) x(t)
Sum Gain
+-
-
11
21
Example 2
Drag a Gain block from Math library to the model window
22
Example 2
Double-click to set gain block parameter = =1 1 4m 0.25
12
23
Example 2
Add integrators to obtain the desired output variable
1m
mx(t) x(t)
Sum Gain
1s
Integrator
x(t) 1s
x(t)
Integrator
+-
-
24
Example 2
Drag Integrator blocks from Continuous library to themodel window
Initial conditions are = 0
13
25
Example 2
Connect gain blocks to integrated signals
Obtain the terms of the right-hand side of the motionequation
c
k
1m
1s
1s
x(t) x(t) x(t)mx(t)
Sum Gain Integrator Integrator
Gain
Gain
+-
-
26
Example 2
Drag new Gain blocks from Math library to the modelwindow
14
27
Example 2
Drag a Scope block from Sinks library to the modelwindow
Connect from the gain block input backwards up to thebranch point
28
Example 2
Double-click on gain blocks to set parameter c = 0.5 andparameter k = 1
15
29
Example 2
Connect all signals and inputs to the summing block
c
k
1m
1s
1s
x(t) x(t) x(t)mx(t)
Sum Gain Integrator Integrator
Gain
Gainkx(t)
cx(t)
+-
-
f(t)
30
Example 2
Drag a Step block from Sources library to the modelwindow
16
31
Example 2
Double-click on Step block to set parameter
For a step input of magnitude = 3 set Final value = 3
32
Example 2
Final Simulink model
17
33
Example 2
Run the simulation in the model window select Startfrom Simulation menu
34
Example 2
Underdamped response with a overshoot of 0.5 and afinal value of 3
Is this expected?
18
35
Example 2
Analysis based on motion equations
Standard form
Natural frequency
Damping ratio
Static gain
+ + =
x(t) c 1
x(t) x(t) f(t)k k km
= =n
k 2
m
= =n
c2 0.5 k
= =
1K 1k
36
Example 2
Damping ratio equal to 0.5 less than 1
Expect underdamped system
Expect overshoot
Static gain is 1
Expect output magnitude match input magnitude
Input and output magnitude 3
Simulation results confirm expectations
19
37
Single tank level system
Qin [m3/s] inlet volumetric flow of the tank
Qout [m3/s] outlet volumetric flow of the tank
h [m] water level in the tank
Example 3
38
Build a Simulink model to predict changes in the tanklevel due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convertfrom volume units to mass units
It is also needed to know the cross-sectional area of thetank in order to determine the volume holdup and hencethe mass holdup in the tank
The mass balance of the simple tank system is given by:
Example 3
( )= in out
d AhQ Q
dt
20
39
The tank has a cylindrical shape constant crosssectional area A = 20 m2
There is no heating effect density assumed constant
The flow Qout through the discharge valve (with crosssection a) is related with the water level in the tank:
The mass balance equation can be rewritten:
Example 3
= = in out in outdh dh
A Q Q A Q Qdt dt
( )= = = =out d out d outQ C a 2gh Q C a 2g h Q k h 2 h
= = = inin out inQ k hdh dh dhA Q Q A Q k h
dt dt dt A
40
Final Simulink model
Example 3
21
41
Null initial conditions (set up through the integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following response
Example 3
( )( )in
H sQ s
42
Two tank level system without interaction
Qin1 [m3/s] inlet volumetric flow of the first tank
Qout1 [m3/s] outlet volumetric flow of the first tank
Qin2 [m3/s] inlet volumetric flow of the second tank
Qout2 [m3/s] outlet volumetric flow of the second tank
h1 [m] water level in the first tank
h2 [m] water level in the second tank
Example 4
22
43
Example 4
44
Build a Simulink model to predict changes in both tanklevels due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convertfrom volume units to mass units
It is also needed to know the cross-sectional area of bothtanks in order to determine the volume holdup and hencethe mass holdup in both tanks
The mass balance of the two tank level system is givenby:
Example 4
( ) ( )= =
1 1 2 2in1 out1 in2 out2
d A h d A hQ Q and Q Q
dt dt
23
45
Both tanks have a cylindrical shape constant crosssectional area A1 = A2 = A = 20 m2
There is no heating effect density assumed constant
The flows Qout1 and Qout2 through the discharge valves(with cross section a) are related with the water level inboth tanks:
The volumetric flow exiting the first tank feeds the secondtank Qout1 = Qin2The mass balance equations of both tanks are given by:
Example 4
= =in1 1 1 1 1 2 21 2Q k h k h k hdh dh
and dt A dt A
= = = =out1 1 1 1 out2 2 2 2Q k h 2 h and Q k h 2 h
46
Final Simulink model
Example 4
24
47
Final Simulink model
Example 4
48
Final Simulink model subsystem
Example 4
25
49
Null initial conditions (set up through the integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following responses
Example 4
( )( )
( )( )
1 2
in1 in2
H s H s and Q s Q s
50
Two tank level system with interaction
Qin1 [m3/s] inlet volumetric flow of the first tank
Qout1 [m3/s] outlet volumetric flow of the first tank
Qin2 [m3/s] inlet volumetric flow of the second tank
Qout2 [m3/s] outlet volumetric flow of the second tank
h1 [m] water level in the first tank
h2 [m] water level in the second tank
Example 5
26
51
Example 5
52
Build a Simulink model to predict changes in both tanklevels due to changes in flow conditions
Develop a mass balance
Volumetric flows a density term is needed to convertfrom volume units to mass units
It is also needed to know the cross-sectional area of bothtanks in order to determine the volume holdup and hencethe mass holdup in both tanks
The mass balance of the two tank level system is givenby:
Example 5
( ) ( )= =
1 1 2 2in1 out1 in2 out2
d A h d A hQ Q and Q Q
dt dt
27
53
Both tanks have a cylindrical shape constant crosssectional area A1 = A2 = A = 20 m2
There is no heating effect density assumed constant
Due to the interaction between the two tanks Qout1 isobtained by the level difference of the two tanks:
The volumetric flow exiting the first tank feeds the secondtank Qout1 = Qin2
The mass balance equations of both tanks are given by:
Example 5
= = out1 1 1 2 1 2Q k h h 2 h h
= =in1 1 1 2 1 1 2 2 21 2Q k h h k h h k hdh dh
and dt A dt A
54
Example 5
Final Simulink model
28
55
Tank 1 is empty and Tank 2 has a level of 1 m (set upthrough the corresponding integrator block)
Unit step change in the inlet flow rate of the tank system
Simulation gives the following responses
Example 5
( )( )
( )( )
1 2
in1 in2
H s H s and
Q s Q s
56
Mass-spring-damper system
Mass m = 4 kg
Damping coefficient c = 2 Ns/m
Spring constant k = 36 N/m
Position initial condition x(0) = 0.5 mVelocity initial condition = 0 m
Example 6
x(0)
29
57
Build a Simulink model of the mass-spring-dampersystem
Develop a force balance using 2nd Newtons law:
Find the system responses to the following inputs:Constant input of 0 N or no inputConstant input of 100 NStep input of 100 N with an initial value of 0, final valueof 100 and step time of 20 sSinusoidal input with amplitude of 100 N and frequencyof 3 rad/s
Write an m-file to plot all the responses in a single figure
Example 6
= mx(t) f(t) cx(t) kx(t)
58
Example 6
Final Simulink model
30
59
Example 6
m-file to plot all the system responses in a single figure
60
Example 6
0 5 10 15 20 25 30 35 40-0.4
-0.2
0
0.2
0.4
0.6Free Response
time (sec)
posi
tion (m
)
0 5 10 15 20 25 30 35 400
1
2
3
4
5Constant Forced Response
time (sec)
posi
tion (m
)
0 5 10 15 20 25 30 35 40-1
0
1
2
3
4
5Step Forced Response
time (sec)
posi
tion (m
)
0 5 10 15 20 25 30 35 40-0.4
-0.2
0
0.2
0.4
0.6Sinusoidal Forced Response
time (sec)
posi
tion (m
)
System responses to the given inputs
31
61
Example 7
Industrial mixing process
Qhot [m3/s] hot volumetric flowQcold [m3/s] cold volumetric flowThot [C] hot temperatureTcold [C] cold temperature
62
Example 7
Build a Simulink model to simulate the temperaturecontrol of a mixing process
The temperature of the mixed flow is given by:
Control flow Q by manipulating Qcold
Control temperature T by manipulating Qhot
Consider volume V = 0.5
( )+ + + = =hot hot cold cold hot cold hot hot cold cold
Q T Q T Q Q T Q T Q T QTdT dTdt V dt V
32
63
Example 7
Final Simulink model
64
Example 7
Final Simulink model
33
65
Example 7
Final Simulink model subsystem
66
Example 7
Final Simulink model subsystem
34
67
Example 7
Run the simulation and plot the responses of T and Q
Modify the values of the PI controllers to improve theresponse: