Sei sulla pagina 1di 43

IE383

Introduction to Simulink
Computer Control Lab
Industrial & Systems Engineering
Rutgers State University

IE383
Simulink (Simulation and Link)
Extension of MatLab
Modeling
Simulating and
Analyzing of dynamic systems
Under a GUI environment
Click-and-Drag Mouse Operations
Block Library
Linear and Non-Linear Analysis
Lab: Focus on Control Systems

IE383
MatLab v.s. Simulink
MatLab + Simulink: Best choice
Schematic (Easy to model complicated
systems)
Simulink
Change Parameters (Text code ):
Matlab (m-file for parameter initialization)
Edit figures:
Simulink (To Workspace)
Matlab (m-file for plot)

IE383
Starting Simulink
Enter simulink in the Matlab command window.
>> simulink
NEW FILE ICON
DESCRIPTION BOX
LIBRARY
BLOCK SET
SEARCH WINDOW
IE383
To see content of a block set, Press + at
the beginning of each toolbox.
Use Ctrl+N or the new file icon to start a
model.
Starting Simulink
THIS IS THE WORKSPACE WHERE YOU
CONSTRUCT YOUR MODEL
IE383
Creating a Block
In the block set categories section of the
simulink library browser simulink group
sources


IE383
Creating the Block (Contd)





Save the file as .mdl file
Continue adding icons
Creating a Block (Contd)
Searching for icons
Search Window
Edit -> FIND prompt

Deleting a block
Selecting the block you wants to
delete
Then by Ctlr+X or the Delete key
IE383
IE383
Example 1: All the blocks that
we need

SOURCES
SIGNAL
ROUTING
SINKS
CONTINUOUS
IE383
Making Connections
Establish Connection between Blocks:
Select the source block(s)
Hold down CTRL key
Left-click on the destination block
For Sources that has multiple destinations:
Move cursor to the Output Ports (>)
Represented by >where the cursor will turn into a
+ sign
IE383
Sine Signal
Generated by the Sine Wave block
Displayed by the Scope
Integrated Sine Signal
Generated by the Integrator block from
Sine Wave block
Displayed by the Scope
Via the Mux
Multiplex the signal in form of scalar,
vector or matrix into a bus
Making Connections (Contd)
IE383
Running Simulation
Click on the play Button (OR)
Use the Key Sequence Ctrl+T (OR)
Simulation Menu Start

Simulation Results
Display the Scope:
Double Click on the Scope Block

IE383
IE383
Handling of Blocks and Lines
Actions Keystokes or Mouse Actions
Copying a block from a library Drag the block to the model window with the left button on the
mouse OR use select the Add selected block from EDIT menu.
Duplicating blocks in a model Hold down the CTRL key and select the block with the left
mouse drag the block to a new location.
Display block's parameters Double click on the block
Rotate a block (clockwise 90 deg
@ each keystroke)
CTRL-R
Changing blocks' names Click on block's label and position the cursor to desired place.
Disconnecting a block
Hold down the SHIFT key while dragging the mouse with the left
button
Drawing a diagonal line
Hold down the SHIFT key while dragging the mouse with the left
button
Dividing a line
Move the cursor to the line to where you want to create the
vertex and use the left button on the mouse to drag the line
IE383
Example2: Simulation of an
Equation

where
x Function of Time
w Frequency ( =5 radians/second)
phi () Phase Angle ( = pi/2)
A Amplitude ( = 2)
) t cos( A ) t ( x = + =
IE383
Drag the following blocks from
Simulink Library to Model Window

Blocks to be dragged to the
model window
Where located in Simulink
library browser
Ramp Sources
Constant Sources
Gain Math Operation
Sum Math Operation
Product Math Operation
Trigonometric Function Math Operation
Mux Signal Routing
Scope Sinks
IE383
Connect the blocks as shown below

Double click on the blocks and enter the appropriate
values. The Cosine value can be selected from the pull
down menu in the pop up window.
The Ramp value is also displayed along with the output
using the Mux tool.
( ) 2cos(5 1.508) x t t = +
IE383
Running the Simulation
Make Connection and Run Simulation
Better Display of the Plots
The Autoscale button on the Scope
window
Redefine the Max Step Side Value in
simulation parameters window

Simulation Results

IE383
Equivalent Matlab Instructions

>> t = (0:0.01:10);
>> A = 2; phi = pi/2; omega = 5;
>> xt = A*cos(omega*t+phi);
>> plot(t, xt);grid

IE383
Exercise 1:
Mass/Spring/Damper system
Consider a system which has a unit step
input, and can be represented by:
x = Ax + Bu
y = Cx + Du

Where , , C = (1 0)
, D = 0

k = 2, m = 1, c = 0.5

x =

IE383
|
|
.
|

\
|
=
m /
B
1
0
dt
dx
|
|
.
|

\
|

=
m / c m / k
A
1 0
Please Do the Following:
1. Model this system using Simulink.
2. Define all matrices in the Workspace using MatLab m-file. Then
use these variables in all the Simulink blocks.
3. See how system response with different coefficients of c = 0.5,
1 and 1.5.
To do this efficiently, we modify m-file created in Part 2.
Then Run Sumulink model created in Part 1.
(Thus, we dont have to change A matrix each time by hand,
which is tedious)
4. Export the data from Simulink to MatLab for Plotting.
(To-Workspace block)
5. (Challenging!) Simulate and plot the response of the system
with three c values. (Use for loop)

IE383
Blocks
Continuous State-Space block
Define Parameters (Double Click on the Block)
Enter A, B, C, D matrices.
Set Initial Condition 0. (0 implies (0 0)
T
)
Sources Step block
Connect Step Output to the Input of State-Space Model
To View the System Output
Connect to Sinks Scope block
Save Model (*.mdl)
Start Simulation

IE383
Your system should look like
this:

IE383
Define Matrices in State-Space





C = (1 0)

D = 0


IE383
0 1
2 0.5
A
| |
=
|

\ .
0
1
B
| |
=
|
\ .
Response of the System

IE383
Autoscale
Define Matrices in Workspace
(Part 2)

IE383
Run m-file that Defines Matrices
in Workspace (Part 2)
>> Exercise2m

IE383
Using Workspace defined Variables in
Blocks (Part 2)

IE383
Export data for MatLab Plot
(Part 4)
Using To Workspace block
Need Both Input and Output of the
System
2 To Workspace blocks
One for Input
One for Output
For MatLab Plot to Understand:
Name Input and Output Values (sim_u &
sim_y)

IE383
Define Variable for Workspace

IE383
Output Values to Workspace

IE383
Export Data
Run the Simulink model with To Workspace blocks
Three variables will be created in the workspace:
Sim_u -created by the first To Workspace block
Sim_y -created by the second To Workspace block
Tout -automatically created by Simulink

Extract the Data
>> t = sim_u.time;
>> u = sim_u.signals.values;
>> y = sim_y.signals.values;

IE383
MatLab Plot
Start a Figure
>> figure
>> hold on
Plot Input as thick blue line
>> plot(t, u, b-, LineWidth,5);
Plot Output as thick red line
>> plot(t, y, r-, LineWidth, 5);
Note on Figure
>> title(Response of System);
>>xlabel(t);
>>ylabel(Response);
>>hold off;
IE383
Simulation Results (Part 5)

IE383
IE383
Exercise 2: Mass-Spring-
Dashpot System




m= equivalent mass of the system
c= damping ratio
k= spring stiffness
f(t)= forcing function in the x-direction
Mathematical model for the system is given by:
f(t) = mx+ cx + kx
IE383
Mass-Spring-Dashpot System
(Contd)

Blocks to be dragged to the
model window
Where located in Simulink
library browser
Step Sources
Gain Math Operations
Sum Math Operation
Integrator Continuous
Scope Sinks
To Workspace Sinks
IE383
Mass-Spring-Dashpot System
(Contd)
Rearranging the equation we get:

X = 1/m(f(t) cx kx)

m= 2
k=0.7
c= 1


IE383
Mass-Spring-Dashpot System
(Contd)
X = 0.5(f(t) 0.7x x)
= 0.5*f(t) 0.35*x 0.5*x





Use CTRL-R to rotate the blocks


Adding a time array from the
simulation
Simulation -> Configurtion Parameters -> Data Import/Export
IE383
IE383
Mass-Spring-Dashpot System
(Contd)
Now let us run the simulation and the
response is :

IE383
Mass-Spring-Dashpot System
(Contd)
What do we understand from the
simulation??

Change the parameters and see
different results

Plot in Matlab
>>who
>>plot(time,simout);grid

IE383

Potrebbero piacerti anche