lab01 get start simulink

Upload: spin-fotonio

Post on 04-Jun-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Lab01 Get Start Simulink

    1/22

  • 8/13/2019 Lab01 Get Start Simulink

    2/22

    ES205 Getting started with Simulink Page 2 of 16

    3) When SIMULINKopens you will see the box called the SIMULINKLibraryBrowser. The Library consistof a number of differentSIMULINKblocks with whicha system model may be

    built.

    To build a model, you first needto create a space to make themodel.

    Click the new model icon in theupper left corner to open a newSIMULINKfile workspace.

    Next, select the SIMULINKicon to

    expand the list of the availableelements that are used to createa system model.

    4) After making the selections in Step 3, the S IMULINKLibrary Browser will showfolders that contain the most commonly used elements you will be using formodel creation.

    Click on each of the following folders and quickly note the elements that arecontained in each.

    -- Continuous-- Discrete-- Functions & Tables-- Math-- Nonlinear-- Signals & Systems-- Sinks-- Sources

    When needed, these elementsmay simply be clicked, dragged,and dropped into the modelworkspace.

  • 8/13/2019 Lab01 Get Start Simulink

    3/22

    ES205 Getting started with Simulink Page 3 of 16

    During Step 3 you also opened a window called Untitled, which is the modelworkspace where the models will be created.

    5) You have not yet created a model, but if you had, you would want to be able tosave the model.

    To save a model, pull downthe Filemenuand select Save_AsorClick on theFile Save Button

    While we won't savea file right now, wewill have you create anew folder to saveany models you will create.

    Create a new folder called,simulink_filesby clicking on

    on the new folder button.and supply the correctname.

  • 8/13/2019 Lab01 Get Start Simulink

    4/22

    ES205 Getting started with Simulink Page 4 of 16

    Part B) Example 1: A Simple Model

    1) The first model you are going to build will solve a simple 1st order differentialequation given by

    )2sin(3 tdt

    dx=

    with an initial conditionx(0) = -1.

    2) To create a model of this equation, we first sketch a simulation diagramofthe mathematical model.

    The simulation diagram will consist of:

    an input --> the forcing function, 3 sin(2t)

    an output --> the solution, dx/dt

    a parameter --> the initial condition, x(0) = -1

    an operator --> integration block

    3) To construct this model in Simulink, will require three elements:-- a Sine Wave Block--an Integrator Block-- a Scope Block

    Locate the Sine Wave under the Sources folder and Click, Drag, and Drop it inthe model workspace window to create the Input Block

    output:x(t)

    x

    dxdtinput:

    3sin(2t)

    I.C.:x(0) = -1

    1s

  • 8/13/2019 Lab01 Get Start Simulink

    5/22

    ES205 Getting started with Simulink Page 5 of 16

    4) Locate the Integrator under the Continuous folder and Click, Drag, and Drop itin the model workspace window to create the Operator Block.

    5) Locate the Scope under the Sinks folder and Click, Drag, and Drop it in themodel workspace window to create the Output Block

  • 8/13/2019 Lab01 Get Start Simulink

    6/22

    ES205 Getting started with Simulink Page 6 of 16

    6) Connecting the blocks.

    Blocks can be connected by dragging a line from the outputof one block to theinputof another block.

    Make the following connections:Output of the Sine Wave --> Input of the Integrator

    Output of the Integrator --> Input of the Scope

    The arrows indicate the direction of the signal flow.

    7) Selecting Simulation Parameters.

    Most blocks have different parameters that are associated with them. To accessthe parameters, simply double-click on the block of interest. This will bring up adialog box which allows the parameters to be changed.

    Double click on the Sine Waveand set the following parameters:

    Amplitude = 3

    Frequency = 2

  • 8/13/2019 Lab01 Get Start Simulink

    7/22

    ES205 Getting started with Simulink Page 7 of 16

    Double click on the IntegratorBlock and set the parameterfor the initial condition.

    x(0) = -1

    Double Click on the ScopeBlock.

    This does not have anyparameters which needsetting, but instead displaysthe scope display screen.

    8) Now that the model has been defined and created, the model simulation isready to run.

    To Start a simulation,pull down the Simulationmenu, and select Start.

    View the output of thesimulation on the Scopewindow.

  • 8/13/2019 Lab01 Get Start Simulink

    8/22

    ES205 Getting started with Simulink Page 8 of 16

    9) Simulation Results

    Your results should looklike the figure.

    Measure the magnitude ofpeaks and valleys and theperiod of the signal.

    Peak = ____________

    Valley = ____________

    Period = ____________

    10) Simulation Verification:

    To verify that this plot represents the solution to the problem, let's solve theequation another way. Either manually, or using Maple, obtain the solution x(t) ofthe ODE with the initial condition

    )2sin(3 tdt

    dx= with x(0) = -1

    Show solution here:

    The result should be:

    This is the function that was plotted in the S IMULINKScope window.

    Save this SIMULINKmodel in the simulink_filesfolder as as Example1.mdl

    ( )ttx 2cos)( 23

    21=

  • 8/13/2019 Lab01 Get Start Simulink

    9/22

    ES205 Getting started with Simulink Page 9 of 16

    Part C: Example 2, a mass, spring, damper system

    1) The second model will use SIMULINKto create a model of a mass-spring-damper system which may be modeled with a 2nd order differential equation.Other parameters of the system include:

    -- initial conditions: x(0) = 0 and dx/dt(0) = 0-- the input f(t) is a step function with magnitude 3 at t=0-- mass, m = 0.25-- damping coefficient, c = 0.5-- spring constant, k = 1

    The model equation:

    )(2

    2

    tfkxdt

    dxc

    dt

    xdm =++

    Assume all units are consistent for the model.

    You will work through the following steps:a) Draw the simulation diagramb) Create and save the SIMULINKModelc) Run the Simulation.

    2) In the space below attempt to draw the simulation diagramfor this model:

  • 8/13/2019 Lab01 Get Start Simulink

    10/22

    ES205 Getting started with Simulink Page 10 of 16

    3) Let's walk through the steps.

    For comparison, start by solving the model equation for the highest orderderivative term.

    xkdtdxctf

    dtxdm = )(2

    2

    The first block you create should be a Sum block, where the output of the Sumblock is the left-hand term of the equation above.

    Now using SIMULINK, Create a new workspace..... File ..... New.....Model

    Locate the Sum Block in the ____________ library and Click, Drag and Drop itinto your new workspace.

    The Sum block is to have 3 inputs. Double click on the Block and set theparameters to rectangularand + - -.

    sum block

    md xdt2

  • 8/13/2019 Lab01 Get Start Simulink

    11/22

  • 8/13/2019 Lab01 Get Start Simulink

    12/22

    ES205 Getting started with Simulink Page 12 of 16

    5) Add two integrators to your Simulation diagram.

    Click, Drop, and Drag two Integrator Blocks into your SIMULINKworkspace fromthe _______________ library.

    Also:

    Set the initial condition parameters to zero for both integrators.Add a scope block to the output of the second integratorConnect the output ports to the input port as shownLabel each of the signals by double clicking on the leader line.

    md xdt2

    1

    m

    d xdt2

    sum block gain

    s

    1

    s

    1dxdt

    x

    Integrator Integrator

  • 8/13/2019 Lab01 Get Start Simulink

    13/22

    ES205 Getting started with Simulink Page 13 of 16

    6) Return Branch Gain Blocks

    In the Simulation Diagram, connect the integrated signals with gain blocks tocreate the terms on the right-hand side of the model equation.

    In SIMULINK, Drag in two additional Gain blocks from the Math library to theworkspace.--Flip these blocks by selecting each block and using...... Format.......Flip Block--Double click on each of the blocks and set the appropriate parameters

    c = 0.5k = 1.0

    --Connect the signal lines:Either Click the gain block input and drag to each of the branch points.

    orCtrl-Click to select the branch point first and drag to the gain inputs.

    --Add appropriate titles to the gain blocks

    md xdt2

    1

    m

    d xdt2

    sum block

    s

    1

    s

    1

    k

    c

    dxdt

    k x

    c

    dxdt

    x

    k = 1.0

    c = 0.5

  • 8/13/2019 Lab01 Get Start Simulink

    14/22

    ES205 Getting started with Simulink Page 14 of 16

    7) Connect all Input Signals.

    In the Simulation Diagram, connect all the input signals to the appropriate inputsof the Sum Block.

    In the SIMULINKworkspace:-- Add a Step Block from the Source library and set its parameters.

    Step time = 0Initial value = 0Final value = 3

    -- Connect the signal lines to the sum Block, paying attention to the signs of theinputs.

    m d xdt2

    1

    m

    d xdt2

    s

    1

    s

    1

    k

    c

    dxdt

    k x

    c

    dxdt

    x+--

    Input:f(t)Output:

    x(t)

  • 8/13/2019 Lab01 Get Start Simulink

    15/22

    ES205 Getting started with Simulink Page 15 of 16

    8) Your completed SIMULINKmodel should look like the following. Complete anymissing titles or labels.

    Save your model as Example2.mdl

    9) Running your simulation

    Double click on the Scope to make its output visible.

    Run your simulation.

    What is it maximum value of x reached?______________

    What is its final value of x reached?__________________

    Is this behavior underdamped, overdamped, or critically damped?

  • 8/13/2019 Lab01 Get Start Simulink

    16/22

    ES205 Getting started with Simulink Page 16 of 16

    This concludes the SIMULINKTutorial Module.

    You are now to complete Part D: Lab 1 Worksheet. To complete theworksheet you are expected to understand and use the terms below.

    Terms used on the worksheet:

    Steady State Value is thefinal value of the system settles at after transientbehavior has dissipated.

    Overshootis characterized as the maximum response swing past the steadystate value.

    Rise time is time required for the system to first reach the steady state value.

    Settling timeis the amount of time the system takes to value settle close to the

    steady state condition (to within approximately 5% of the step size).

    .

    RiseTime

    +/- 5% of step

    SettlingTime

    Overshoot Steady StateValue

    time

  • 8/13/2019 Lab01 Get Start Simulink

    17/22

    ES205 Lab 1 Worksheet Page 1 of 6

    Name __________________________Section _______ C M _____________

    Lab Partners: ________________ __________________ _______________

    Part D: Lab 1 Worksheet

    ES205 Analysis and Design of Engineering Systems

    1) Mass-Spring-Damper Model:Below you will explore how changing each of the three parameters, m, c, and k ,affect the system response of the spring-mass-damper model created in Part C.

    Varying the mass, m:In the space below, make a prediction. How do you think changing the mass, m,of the system will affect its dynamic behavior?

    Now using your SIMULINK model, vary the value of the mass, m, using themultipliers given below, while keeping k and c constant. Then on the graphbelow sketch and label each response.

    Use Mass values: m/5 m/2 1.0*m 2.0*m and 5*m

    Summary: Give a short summary which qualitatively describes how changingthe mass affected the system response. Include qualitative reference to theovershoot, settling time, and steady state value.

    0 1 2 3 4 5 6 7 8 9 100

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    5

  • 8/13/2019 Lab01 Get Start Simulink

    18/22

    ES205 Lab 1 Worksheet Page 2 of 6

    Varying the damping constant, c:Make another prediction. How will changing the damping constant, c, of thesystem affect its dynamic behavior?

    Now using your SIMULINKmodel, vary the value of the mass, c, using themultipliers given below, while keeping k and m constant. Then on the graphbelow sketch and label each response.

    Use Damping Constants: c/5 c/2 1.0*c 2.0*c and 5*c

    Summary: Give a short summary which qualitatively describes how changingthe damping constant affects the system response. Include qualitative referenceto the overshoot, settling time, and steady state value.

    0 1 2 3 4 5 6 7 8 9 100

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    5

  • 8/13/2019 Lab01 Get Start Simulink

    19/22

    ES205 Lab 1 Worksheet Page 3 of 6

    Varying the elastic coefficient, k:Make a prediction: How will changing the elastic coefficient, k, of the systemaffect its dynamic behavior?

    Now using your SIMULINKmodel, vary the value of the elastic coefficient, k, usingthe multipliers given below, while keeping m and c constant. Then on the graphbelow sketch and label each response.

    Use Elastic Coef values: k/5 k/2 1.0*k 2.0*k and 5*k

    Summary: Give a short summary which qualitatively describes how changingthe elastic coefficient affected the system response. Include qualitative referenceto the overshoot, settling time, and steady state value.

    0 1 2 3 4 5 6 7 8 9 10

    0

    2

    4

    6

    8

    10

    12

    14

    16

  • 8/13/2019 Lab01 Get Start Simulink

    20/22

  • 8/13/2019 Lab01 Get Start Simulink

    21/22

    ES205 Lab 1 Worksheet Page 5 of 6

    Now using your Simulation diagram, create the SIMULINKmodel for this electricalsystem using the values:

    R = 3L = 1

    C =0.5and E(t),which is a pulse defined as

    Add Scope Blocks to display both outputs, iand e, as well as the input voltage,E(t). Make sure you include appropriate labeling of the blocks, signals, and I/O.

    Run the simulation for 0< t < 10

    Sketch the shape of the output signals below:

    Now experiment with your model by varying each of the component parameters,R, L, and C. Describe the effect each has on the system response.

    Effect of Varying R:

    Effect of Varying L:

    Effect of Varying C:

    E(t)2

    t

    1 5

    e

    t t

    i

  • 8/13/2019 Lab01 Get Start Simulink

    22/22