View
213
Download
0
Category
Preview:
Citation preview
8/20/2019 Simulink-02-01
1/53
Department of Mechatronics Engineering
Module IV:SIMULINK and Neuro-Fuzzy Toolboxes
MATLAB &SIMULINK with
Applications
8/20/2019 Simulink-02-01
2/53
Department of Mechatronics Engineering
Session 2:Getting Started with Simulink
SIMULINK
8/20/2019 Simulink-02-01
3/53
Department of Mechatronics Engineering
Session Otlines
• Subsytems
• Masking
• Discrete System
8/20/2019 Simulink-02-01
4/53
8/20/2019 Simulink-02-01
5/53
Department of Mechatronics Engineering
S!s"stems
Metho% of reating S!s"stems
'here are two method #or creating
subsystems:• (ncapsulating a Subsystem ! portion o# existing model isencapsulated to be
a subsystem• &se Subsystem blocks #rom Signals )System
*ibrary
8/20/2019 Simulink-02-01
6/53
Department of Mechatronics Engineering
S!s"stems
Encapslating S!s"stemsSuppose we want to make our primitive model o#mass+spring+damper as a subsystem
8/20/2019 Simulink-02-01
7/53Department of Mechatronics Engineering
S!s"stems
Encapslating S!s"stems 'o encapsulate a portion o# a Simulink model%select all the blocks and signal line to be includedin the subsystem using a bounding box using ourmouse
bounding box
8/20/2019 Simulink-02-01
8/53Department of Mechatronics Engineering
S!s"stems
Encapslating S!s"stems,hoose ,reate Subsystem under (dit menu
-ew subsystem
8/20/2019 Simulink-02-01
9/53Department of Mechatronics Engineering
S!s"stems
Encapslating S!s"stems 'o view or edit a subsystem% double+click theblock ! new window will appear
8/20/2019 Simulink-02-01
10/53Department of Mechatronics Engineering
S!s"stems
S!s"stems Bloc's.#% when building a model% we know that we willneed a subsystem% it will more convenient tobuild a subsystem in a subsystem directly
Drag a Subsystem /lock #rom 0orts )Subsystem *ibrary to the model window
8/20/2019 Simulink-02-01
11/53Department of Mechatronics Engineering
S!s"stems
S!s"stems Bloc'sDouble click the subsystem to open subsystemwindow
/uild subsystem using the standard procedure
8/20/2019 Simulink-02-01
12/53Department of Mechatronics Engineering
S!s"stems
S!s"stems Bloc's
&se .nport /locks #or all signals enteringsubsystem and 1utport /locks #or all signalsleaving the subsystem "/oth blocks are #rom 0ort) Subsytem *ibrary$
ou may change the label o# .nport and 1utpor,lose the subsystem window i# we 3nished
building subsystem
8/20/2019 Simulink-02-01
13/53Department of Mechatronics Engineering
Mas'ing
oncept
Masking permits us to treat a subsystem as i# itwas a simple block
! mask is a custom user inter#ace #or asubsystem that hides the subsystem4s
contents% making it appear to the user as anatomic block with its own icon andparameter dialog box
8/20/2019 Simulink-02-01
14/53
Department of Mechatronics Engineering
Mas'ing
oncept
We make a masked subsystem #or the #ollowingreason:• 'here is an algorithm which we want to hide#rom
other user • 'o prevent unintended modi3cation o#subsystems by
hiding their contents behind a mask*et4s build a spring+mass masked block
8/20/2019 Simulink-02-01
15/53
Department of Mechatronics Engineering
Mas'ing
1pen a new model workspace% and drag thesubsystem o# the primitive model into it
8/20/2019 Simulink-02-01
16/53
Department of Mechatronics Engineering
Mas'ing
Select the subsystem model and then chooseMask under (dit menu #rom the new modelwindow menu bar
8/20/2019 Simulink-02-01
17/53
Department of Mechatronics Engineering
Mas'ing
Mask (ditor dialog box consists o# #our tabbedpages• .con• .nitiali5ation
• 0arameters• Documentation
8/20/2019 Simulink-02-01
18/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor Docmentation (age
'he page consists o#three 3eld !ll o# the3elds are optional oumay enter as shown in
the 3gure
'he Docmentation pane enables you to de3neor modi#y the type% description% and help text #ora masked block
8/20/2019 Simulink-02-01
19/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor (arameters (age 'he page is used to set parameters o# block insubsystem underlying the masked block
6or our mass+spring+damper% we have the#ollowing parameters:• Mass% symbol: m% editable by user• Damper% c% editable• Spring% k% editable
'o add a variable% clickadd icon then enter allthe necessary 3eld
add icon
delete icon
8/20/2019 Simulink-02-01
20/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor (arameters (age
8/20/2019 Simulink-02-01
21/53
Department of Mechatronics Engineering
Mas'ing
Mas' Initiation (age 'he Initiali)ation pane allows you to enterM!'*!/ commands that initiali5e the maskedsubsystemSimulink executes the initiali5ation commandswhen it• *oads the model• Starts the simulation or updates the blockdiagram• 7otates the masked block• 7edraws the block4s icon "i# the mask4s iconcreation
code depends on variables de3ned in the
initiali5ation code$
8/20/2019 Simulink-02-01
22/53
Department of Mechatronics Engineering
Mas'ing
Mas' Initiation (age
6or our example% leave this page empty since wewant to make the parameters are editablethrough block parameters
6or example% i# wewant our maskedsystem has the
#ollowing value:m89c82k89;
'ype that parametersin initiali5ationcommands
8/20/2019 Simulink-02-01
23/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor Icon (age 'he Mask (ditor4s Icon pane enables you to createicons that can contain descriptive text% statee
8/20/2019 Simulink-02-01
24/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor Icon (age
Drawing comman%s 'his 3eld allows us to enter commands that draw
the block4s icon Simulink provides a set o#commands that can display text% one or moreplots% or show a trans#er #unction We may usethe #ollowing commands: text% plot% displ% dpoly%
etc as shown in the example command We mustuse these commands to draw your icon
8/20/2019 Simulink-02-01
25/53
Department of Mechatronics Engineering
Icon options 'hese controls allow you to speci#y the attributeso# the block icon
6rame 'ransparency
7otation &nit
Mas'ing
Mas' E%itor Icon (age
8/20/2019 Simulink-02-01
26/53
Department of Mechatronics Engineering
Mas'ingMas'ing
Mas' E%itor Icon (age*et draw the #ollowing 3gure #or our maskedsubsystem
Set the #ollowing
icon option:6rame: =isible
'ransparency:1pa
8/20/2019 Simulink-02-01
27/53
Department of Mechatronics Engineering
plot">;9 ;9?%>;2 ;@?$plot">;A ;B ;B ;A ;A?%>;2 ;2 ;@ ;@ ;2?$
plot">;9 ;2?%>;A ;A?$plot">;C ;2 ;2 ;C?%>;C ;C ; ;?$plot">9 2 2 C C A?%>B B @ E B B?$plot">;C ;A?%>;A ;A?$plot">;B ;F?%>; ;?$
text"%%m$text"2%C%c$text"2%@%k$text"@%E%#$
Mas'ingMas'ing
Mas' E%itor Icon (age 'ype the #ollowing commands into commands 3eld
8/20/2019 Simulink-02-01
28/53
Department of Mechatronics Engineering
Mas'ingMas'ing
Mas' E%itor Icon (ageWe will get the #ollowing masked subsystem:
8/20/2019 Simulink-02-01
29/53
Department of Mechatronics Engineering
Mas'ingMas'ing
Mas' E%itor Icon (ageWe may also displaying a ti# image on a block iconusing the #ollowing drawing command:
image"imread"H3leInameti#4$$
8/20/2019 Simulink-02-01
30/53
Department of Mechatronics Engineering
,lose the mask editor% now% our subsystem looklike blocks o# Simulink library Double+click to seethe eJect o# the masking
Mas'ing
'i
8/20/2019 Simulink-02-01
31/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor Docmentation (age
M 'i
8/20/2019 Simulink-02-01
32/53
Department of Mechatronics Engineering
Mas'ing
Mas' E%itor Docmentation (age
Di S
8/20/2019 Simulink-02-01
33/53
Department of Mechatronics Engineering
Discrete S"stem
oncept
Discrete system is dynamical system that canbe described using diJerence e
8/20/2019 Simulink-02-01
34/53
Department of Mechatronics Engineering
Discrete S"stem
oncept
Simulink has the ability tosimulate discrete system%
including system whosecomponents operate atdiJerent rates "multi rate$and system that mix
discrete and continuouscomponents "hybridsystem$
Di t S t
8/20/2019 Simulink-02-01
35/53
Department of Mechatronics Engineering
Discrete S"stem
*et4s build a model and simulate the #ollowingsystem:
)k (u)1k (x094.0)1k (xsin05.0)k (x
)1k (x1.0)1k (x)k (x
212
211
+−+−−=
−+−=
We may construct a Simulink model by using• primitive blocks• trans#er #unction block • state variable model
'he process is assumed to have a sample timeo# ;9 sec
Di t S t
8/20/2019 Simulink-02-01
36/53
Department of Mechatronics Engineering
(rimiti*e Bloc's
Discrete S"stem
We can build a block diagram as the #ollowing3gure:
0.094
u(k)
+ + z
10.1
x2 (k)
x1 (k)
z
1
x2 (k-1) x
1 (k-1)
+ +
0.05sinx1!k"1#$
-
!%ources#
!&ser"defined functions#
!'iscrete#
!(ath# !(ath#
Di t S t
8/20/2019 Simulink-02-01
37/53
Department of Mechatronics Engineering
(rimiti*e Bloc's
Discrete S"stem
'here#ore% we have the #ollowing Simulinkmodel
-ext% we should de3ne the #"u$ #unction andsample time
Di t S t
8/20/2019 Simulink-02-01
38/53
Department of Mechatronics Engineering
Discrete S"stem
Double click the #"u$ block% then modi#y thedesired #unction and sampling time ,lick 1K toclose the window
;;Lsin"u$
;9
(rimiti*e Bloc's
Di t S t
8/20/2019 Simulink-02-01
39/53
Department of Mechatronics Engineering
Discrete S"stem
'he Simulink model become as #ollows:
(rimiti*e Bloc's
Di t S t
8/20/2019 Simulink-02-01
40/53
Department of Mechatronics Engineering
Double click the unitdelay blocks% then setsample time to ;9
Do the same process #orother blocks: sum% gainand source
Discrete S"stem
(rimiti*e Bloc's
Di t S t
8/20/2019 Simulink-02-01
41/53
Department of Mechatronics Engineering
/e#ore we run the Simulink model% we shouldcare#ully determine the step si5e o# thesimulation parameter especially when we use 3x
step.n general% we can select the step si5e at integero# multiples o# the shortest system4s sampletime
.n our example% the sample time is ;9 so wecan select ;9 as step si5e 'hen we cansimulate the model
Discrete S"stem
(rimiti*e Bloc's
Discrete S stem
8/20/2019 Simulink-02-01
42/53
Department of Mechatronics Engineering
Discrete S"stem
*et4s build a model and simulate the #ollowingsystem:
)k (u)1k (x094.0)1k (xsin05.0)k (x
)1k (x1.0)1k (x)k (x
212
211
+−+−−=
−+−=
.n 5+domain%
( )[ ])z(U)z(Xsin05.0094.0z
z)z(X
)z(X1z
1.0
)z(X
12
21
+−
−
=
+
=
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
43/53
Department of Mechatronics Engineering
Discrete S"stem
'hen we can construct the #ollowing blockdiagram:
We can make the discrete model easily based onthis block
!(ath#!'iscrete#
!%ources#
!%inks#!&ser"defined functions#
)!*1 #
U(z) X 2 (z)
+ - 094.0zz
−
X 1 (z)1z
z1.0
+
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
44/53
Department of Mechatronics Engineering
Discrete S"stem
'here#ore% we have the #ollowing Simulinkmodel
-ext% we should de3ne the #"u$ #unction andsample time
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
45/53
Department of Mechatronics Engineering
Discrete S"stem
Double click the #"u$ block% then modi#y thedesired #unction and sampling time ,lick 1K toclose the window
;;Lsin"u$
;9
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
46/53
Department of Mechatronics Engineering
Discrete S"stem
'he Simulink model become as #ollows:
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
47/53
Department of Mechatronics Engineering
Discrete S"stem
Double click the discretetrans#er #unctions% thenmodi#y the trans#er#unction parameters andsample time
1 0$
1 "0.094$
0.1
0.1 0$
1 1$
0.1
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
48/53
Department of Mechatronics Engineering
Discrete S"stem
'he Simulink model become as #ollows:
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
49/53
Department of Mechatronics Engineering
Discrete S"stem
/e#ore we run the Simulink model% we shouldcare#ully determine the step si5e o# thesimulation parameter especially when we use 3x
step.n general% we can select the step si5e at integero# multiples o# the shortest system4s sampletime
.n our example% the sample time is ;9 so wecan select ;9 as step si5e 'hen we cansimulate the model
Transfer +nction
Discrete S"stem
8/20/2019 Simulink-02-01
50/53
Department of Mechatronics Engineering
Discrete S"stem
Simulink also has capability to handel discretesystems with involve subsystems that operateat diJerent
'he Simulink sample+time color capability
provides help in keeping track o# sample tiems
'o activates the #eature% select6ormat:0ortSignals Display and then check
Sample time colors
Mltirate Discrete Time
Discrete S"stem
8/20/2019 Simulink-02-01
51/53
Department of Mechatronics Engineering
Discrete S"stem
,"!ri% S"stem
8/20/2019 Simulink-02-01
52/53
Department of Mechatronics Engineering
,"!ri% S"stem
Mixed continuous and discrete systems arecomposed o# both sampled and continuousblocks Such systems can be simulated using
any o# the integrationmethods% although certain methods are moreeNcient and accurate than others
6or most mixed continuous and discretesystems% the 7unge+Kutta variable+stepmethods% ode2C and odeA% are superior to theother methods in terms o# eNciency andaccuracy
8/20/2019 Simulink-02-01
53/53
En% of Session -
+rther .ea%ing• &sing Simulink
Recommended