me 341 simulink tutorial

Upload: abantojl

Post on 07-Apr-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 ME 341 Simulink Tutorial

    1/14

    Dr. Jorge L. Abanto-Bueno ME3411

    ME 341 Engineering Systems Dynamics

    Mechanical Engineering Department

    Bradley University

    Simulink1 Tutorial

    I. Introduction

    Simulink is a software package that provides a graphical user interface (GUI) for modeling

    dynamic models as block diagrams to simulate and analyze their time-dependant response.

    With Simulink, linear and nonlinear systems can be modeled in continuous or discrete

    time. Simulink has also capabilities to be used in controls, signal processing,

    communications, and other complex systems. It includes a comprehensive block library of

    sinks, sources, linear and nonlinear components, and connectors. In addition, Simulink

    allows the user to create his own blocks.

    To simulate a dynamic system, first, a block diagram is created using the Simulink model

    editor. Remember that a block diagram is the graphical representation of the time-

    dependant mathematical relationships between the systems inputs, states, and outputs.

    Then Simulink is commanded to simulate the system represented by the block diagram

    from a specified start time to a specified stop time.

    The goal of this tutorial is to introduce the basic procedure to create linear models in

    Simulink, and simulate and analyze their dynamic response. The student is encouraged to

    go beyond this tutorial to learn more advanced blocks of this powerful computational tool.

    II. Construction of a Simulink Model

    1. Starting Simulink

    The first step to start Simulink is to start MATLAB. Then Simulink can be started by

    either

    clicking on the Simulink icon (MATLAB toolbar)

    or

    typing theSimulink2 at the prompt

    1 MATLAB and Simulink are registered trademarks of The MathWorks, Inc.2Courierfont is used throughout this tutorial to represent MATLAB or Simulink commands or names

  • 8/6/2019 ME 341 Simulink Tutorial

    2/14

    Dr. Jorge L. Abanto-Bueno ME3412

    The Simulink Library Browser window appears on the computer screen (see Figure 1).

    This library browser contains numerous blocks grouped by general classes of functions.

    For instance, the Integrator block is in the Continuous library; the Sum and Gain

    blocks are in theMath Operationslibrary. TheSourceslibrary contains common input

    functions (e.g., ramp, signal generator, sine wave, step, etc.), theConstant block, theFrom

    Workspaceblock (used to input variables defined in a MATLAB workspace), and theClock

    block that is used to send the simulation time to MATLAB workspace. TheSinks library

    contains, among others, the To Workspace block, which allows sending variables to a

    MATLAB workspace, and theScope block that displays variables as the simulated system

    responds to an input. The student is recommended to get familiar with all these blocks.

    Figure 1. Simulink Library Browser Window

  • 8/6/2019 ME 341 Simulink Tutorial

    3/14

    Dr. Jorge L. Abanto-Bueno ME3413

    2. Creating a Model in Simulink

    To create a new model, click the New icon on the Library Browsers toolbar or choose New

    from the library windows File menu and selectModel (see figures below).

    The new model window appears on the computer screen

    Depending on the specific model that you want to construct, you will need to copy blocks

    from the different Simulink libraries into the new model window.

    Example 1. Consider the function tx sin3 , create a model that calculates and displaysx , x , x and x for s250 t . The model should be able to plot all the variables and sendthe values of t , x and x variables to a MATLAB workspace.

    Solution: The block diagram for this problem is given below

    dt dt tsin 3 xx dt xx

    New model icon

  • 8/6/2019 ME 341 Simulink Tutorial

    4/14

    Dr. Jorge L. Abanto-Bueno ME3414

    You need to copy blocks into the new model window from the following block libraries

    (Simulink Library Browser window):

    Sourceslibrary: theSine Waveand theClockblocks

    Sinks library: The Scopeand theTo Workspaceblocks

    Continuouslibrary: TheIntegratorblock

    Signal Routing library: The Mux block

    TheMuxblock arranges the input signals (scalar, vector or matrix) to be displayed by the

    Scopeblock. TheClock block in conjunction with theTo Workspace block allows you to

    send (and save) the variable t to a MATLAB workspace

    To copy theSine Wave block into the new model window, first click theSourceslibrary

    at the Simulink Library Browser to show all the blocks in this library. Then click theSine

    Waveblock to select it. Below is shown how the Library Browser should look

    Simulinklibrary

    Sine Waveblock

    Sources

    library

  • 8/6/2019 ME 341 Simulink Tutorial

    5/14

    Dr. Jorge L. Abanto-Bueno ME3415

    Drag the Sine Wave block from the library browser and drop it in the new model

    window. Copy the rest of the blocks in a similar manner from their respective libraries.

    Youll need to copy theIntegratorand theTo Workspace blocks three times. The model

    window should look like the figure below

    You should notice that there is one > symbol on each side of the Integratorblock. The

    Mux block has two > symbols on the left and one > symbol on the right. The Scopeand the

    To Workspace blocks have only one > symbol on the left. The Sine Waveblock has only

    one > symbol on the right. The > symbol pointing out of a block is an output port (i.e.,

    output signal); if the symbol points toward a block, its an input port(i.e., input signal). A

    signal travels from an output port and into an input port of another block through a

    connecting line. When the blocks are connected the port symbols disappear.

    Since in this example you were asked to display four variables (i.e., x , x , x and x ), the

    number of input ports on the left of theMuxblock should be increased from two (default

    value) to four. To do this, double-click on theMux block. The block parameters dialog box

    appears on the computer screen. Type 4 at the number of inputs box and then clickOK.

  • 8/6/2019 ME 341 Simulink Tutorial

    6/14

    Dr. Jorge L. Abanto-Bueno ME3416

    You will need to resize theMux block to accommodate all the input ports: Left-click the

    block, then drag any of its selection handles while holding down the left mouse button. A

    dotted rectangle shows the actual size of the block as it is increased or decreased. When

    you release the mouse button, the block is resized.

    The next step is to connect the blocks. To connect the Sine Wave block to the

    Integratorblock, position the pointer over the output port on the right side of the

    Sine Wave block (notice that cursor shape changes to crosshair). Holding down the

    left button of the mouse, move the cursor to the input port of theIntegratorblock.

    Repeat the same procedure to connect the rest of the blocks with each other as

    shown in the figure below

  • 8/6/2019 ME 341 Simulink Tutorial

    7/14

    Dr. Jorge L. Abanto-Bueno ME3417

    Now, you need to define the parameters of the sine wave function. Open the parameters

    dialog box of theSine Waveblock by double-clicking the block. Since in this example the

    input sine function is tsin3 , you only need to change the value of the amplitude of thesine wave from 1 to 3. The block parameters dialog box should look like the figure below

    Now, lets run the simulation for 30 seconds. First, open the Configuration Parameters

    dialog box by choosing Configuration Parameters from the Simulation menu. On the

    dialog box that appears, change the stop time from 10.0 (its default value) to 30.0, then

    close the dialog box by clicking OK.

  • 8/6/2019 ME 341 Simulink Tutorial

    8/14

    Dr. Jorge L. Abanto-Bueno ME3418

    Change the name of the variables of the three To Workspace blocks from simout, simout1

    and simout2 to time, displacementand velocity, respectively. You will also need to change theformat that is used to save these variables from StructuretoArray. Make these changes

    for the three To Workspace blocks by following the procedure used to change the

    parameters of the Mux block. For instance the parameters dialog box of the To Workspace

    block containing initially the variable simout1 should look like the figure below after the

    changes

  • 8/6/2019 ME 341 Simulink Tutorial

    9/14

    Dr. Jorge L. Abanto-Bueno ME3419

    Now, double-click theScopeblock to open its display window. Finally, start the simulation

    by clicking the Starticon on the model toolbar.

    The display of theScope block should look like the figure below

    Start simulation icon

  • 8/6/2019 ME 341 Simulink Tutorial

    10/14

    Dr. Jorge L. Abanto-Bueno ME34110

    TheWorkspaceof MATLAB should have the following variables

    You can write a small M-file to generate your own graphs of the outputs of your model. For

    instance, below is shown an M-file that uses the subplot command to graph the outputdisplacement and velocity as a function of time. This M-file also saves the two graphs as a

    BMP file.

  • 8/6/2019 ME 341 Simulink Tutorial

    11/14

    Dr. Jorge L. Abanto-Bueno ME34111

    Below are shown the graphs

    Example 2.Consider the mechanical system shown in the figure below. The system is at

    rest for 0t . At 0t an impulse-force of 8 N is applied to the mass. The impulse lasts 0.06

    seconds. The displacementx is measured from the equilibrium position just before the

    mass is hit by the impulse force. Find the mathematical model of the system, draw a block

    diagram to represent it, and plot the displacement and velocity of the mass during the first

    25 seconds.

  • 8/6/2019 ME 341 Simulink Tutorial

    12/14

    Dr. Jorge L. Abanto-Bueno ME34112

    Solution: The mathematical model is give by the following equation

    tfKxxBxM a The block diagram for the system is given below

    The model constructed following the steps presented in example 1 is shown in the

    figure below

    The output variables (i.e., displacement and velocity of the mass) displayed by the scope is

    shown in the figure below

    dt dt tfa M1 xx xB

    K

  • 8/6/2019 ME 341 Simulink Tutorial

    13/14

    Dr. Jorge L. Abanto-Bueno ME34113

    After examining the Simulink model, you can see that blocks from the following libraries

    have been used:

    Sourceslibrary: the Pulse Generator block (the Clockblock was not used because

    it was not requested to send any variable to the MATLAB Workspace)

    Sinkslibrary: The Scopeblock

    Math Operations library: The Sum and Gain blocks

    Continuouslibrary: The Integratorblock

    Signal Routinglibrary: The Muxblock

    You should have noticed that two of the gain blocks (damper and spring) have been

    rotated 180 degrees with respect to its default orientation. This has been done by right-

    clicking on the corresponding block and then selecting flip blockfrom the formatmenu.

    In this case the applied load was modeled using thePulse Generator block. The dialog

    box containing the parameters for this block is shown below

  • 8/6/2019 ME 341 Simulink Tutorial

    14/14

    Dr. Jorge L. Abanto-Bueno ME34114