bab10 - the model-wide utilities library

Upload: cakmad69

Post on 01-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    1/11

    Introduction to Simulink with Engineering Applications 10−1Copyright © Orchard Publications

    Chapter 10

    The Model−Wide Utilities Library

    his chapter is an introduction to the Model−Wide Utilities library. This is the ninth libraryin the Simulink group of libraries and contains the Linearization of Running Models Sub−Library, the Documentation Sub−Library, and the Modeling Guides Sub−Library. We

    will describe the function of each block included in this library and we will perform simulationexamples to illustrate their application.

     

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    2/11

    Chapter 10 The Model−Wide Utilities Library

    10−2  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    10.1 The Linearization of Running Models Sub−Library

    The Linearization of Running Models Sub−Library contains the blocks described in Subsections10.1.1 and 10.1.2 below.

    10.1.1 The Trigger− Based Linearization Block

    The Trigger− Based Linearization block, when triggered, invokes the MATLAB functions lin-

    mod or dlinmod to create a linear model for the system. No trimming* is performed. The linearmodel is stored in the base workspace as a structure, along with information about the operatingpoint at which the snapshot was taken. Multiple snapshots are appended to form an array of struc-

    tures.

    The name of the structure used to save the snapshots is the name of the model appended by_Trigger_Based_Linearization, for example, vdp_Trigger_Based_Linearization. The structure hasthe fields shown in the Help menu for this block.

     Example 10.1

    We will use a Trigger−Based Linearization block to extract the linear model for the model shownin Figure 10.1.

    Figure 10.1. Model for Example 10.1

    This is the same model as that of Figure 3.4, Example 3.2, Chapter 3, Page 3−4, where with theexecution of the command [A,B,C,D]=linmod('Figure_3_4') the linear model in the form of thestate−space MATLAB displayed the four matrices as

    A =

    * The trim function uses a Simulink model to determine steady−state points of a dynamic system that satisfy input,output, and state conditions that we can specify. For details please type help trim  in MATLAB’s CommandWindow.

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    3/11

    Introduction to Simulink with Engineering Applications 10−3Copyright © Orchard Publications

    The Linearization of Running Models Sub−Library

      -5 -6 -1

      1 0 0

      0 1 -2

    B =

      1

      0  0

    C =

      0 1 0

    D =

      0

    and thus the model of Figure 10.1 can be represented as

    Next, let us reconsider the model of Figure 10.1 shown as Figure 10.2 where we have included aTrigger−Based Linearization block triggered by a Pulse Generator block whose period is arbitrarilyspecified for 10 seconds.

    Figure 10.2. Model for Example 10.1 with Trigger−Based Linearization

    For the model of Figure 10.2, we execute the simulation command, we save this model asFigure_10_2.mdl, and in MATLAB’s Command Window we type and execute the command

    Figure_10_2_Trigger_Based_Linearization

    MATLAB displays the following:

    Figure_10_2_Trigger_Based_Linearization =

    a: [3x3 double]

      b: [3x1 double]

    5–   6–   1–

    1 0 00 1 2–

    x

    1

    00

    u+=

    y 0 1 0   x 0   u+=

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    4/11

    Chapter 10 The Model−Wide Utilities Library

    10−4  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

      c: [0 1 0]

      d: 0

      StateName: {3x1 cell}

      OutputName: {'Figure_10_2/Out1'}

      InputName: {'Figure_10_2/In1'}

      OperPoint: [1x1 struct]

      Ts: 0

    We observe that a, b, c, and d indicate the sizes of the state−space matrices A, B, C, and Drespectively.

    10.1.2 The Time−

     Based Linearization Block

    The Time− Based Linearization block invokes the MATLAB functions linmod or dlinmod tocreate a linear model for the system when the simulation clock reaches the time specified by theLinearization time parameter. No trimming is performed. The linear model is stored in the baseworkspace as a structure, along with information about the operating point at which the snapshot

    was taken. Multiple snapshots are appended to form an array of structures.The name of the structure used to save the snapshots is the name of the model appended by_Timed_Based_Linearization, for example, vdp_Timed_Based_Linearization. The structure hasthe fields shown in the Help menu for this block.

     Example 10.2

    The model shown in Figure 10.3 is the same model as that of Figure 10.1, Example 10.1. We willuse a Time-Based Linearization block to extract its linear model.

    We begin by adding a Time-Based Linearization block with the linearization time arbitrarily setfor 2 seconds, and the new model is now as shown in Figure 10.4.

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    5/11

    Introduction to Simulink with Engineering Applications 10−5Copyright © Orchard Publications

    The Linearization of Running Models Sub−Library

    Figure 10.3. Model for Example 10.2

    Figure 10.4. Model for Example 10.2 with Timed−Based Linearization block

    For the model of Figure 10.4, we execute the simulation command, we save this model asFigure_10_2.mdl, and in MATLAB’s Command Window we type

    Figure_10_4_Timed_Based_Linearization

    and when this command is executed MATLAB displays the following:

    Figure_10_4_Timed_Based_Linearization =

    a: [3x3 double]

      b: [3x1 double]

      c: [0 1 0]

      d: 0

      StateName: {3x1 cell}

      OutputName: {'Figure_10_4/Out'}

      InputName: {'Figure_10_4/In'}

      OperPoint: [1x1 struct]

      Ts: 0

    We observe that a, b, c, and d indicate the sizes of the state-space matrices A, B, C, and Drespectively.

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    6/11

    Chapter 10 The Model−Wide Utilities Library

    10−6  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    We can use state and simulation time logging to extract the model states and inputs at operatingpoints. For example, suppose that we want to get the states of the Figure_10_4 model at lineariza-tion times of 3 seconds and 7 seconds. This can be done with the following steps:

    1. We open the model and drag an instance of this block from the Model−Wide Utilities library

    and drop the instance into the model.2. We open the block's parameter dialog box and set the Linearization time to .

    3. We open the model's Configuration Parameters dialog box from the Simulation drop menu andwe select the Data Import/Export pane.

    4. We check States and Time on the Save to Workspace control panel, we leave all other param-eters in their default state, and we click on OK to confirm the selections and close the dialogbox.

    5. We start the simulation.

    6. At the end of the simulation, we type and execute whos in MATLAB’s Command Window,and the following variables appear in the MATLAB workspace:

    Figure_10_4_Timed_Based_Linearization, tout, and xout.

    7. We obtain the indices to the operating point times by entering and executing the following inMATLAB’s Command Window:

    ind1 = find(Figure_10_4_Timed_Based_Linearization(1).OperPoint.t==tout);

    ind2 = find(Figure_10_4_Timed_Based_Linearization(1).OperPoint.t==tout);

    We type and execute whos in MATLAB’s Command Window, and the indices ind1 and ind2are now included in the MATLAB workspace:

    8. We obtain the state vectors at the operating points by entering and executing the following inMATLAB’s Command Window:

    x1 = xout(ind1,:); x2 = xout(ind2,:);

    10.2 The Documentation Sub−Library

    The Documentation Sub−Library contains the blocks described in Subsections 10.2.1 and 10.2.2

    below.10.2.1 The Model Info Block

    The Model Info block displays revision control information about a model as an annotation blockin the model's block diagram.

    3 7[ ]

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    7/11

    Introduction to Simulink with Engineering Applications 10−7Copyright © Orchard Publications

    The Documentation Sub−Library

     Example 10.3

    The model in Figure 10.5 solves the non-linear equation

    Figure 10.5. Model for Example 10.3

    We would like to add a Model Info block to indicate that this model was created by John Smithon 02/16/06 and was last modified by Bill Johnson on 04/27/06.

    We drag a Model Info block into the model of Figure 10.5, we double−click it, and on the ModelInfo dialog box shown in Figure 10.6 we enter the desired information. The model now appears asshown in Figure 10.7.

    Figure 10.6. Model Properties and Text for the Model Info block

    f z( )   z2

    4z 3 z z zcos–sin+ + +=

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    8/11

    Chapter 10 The Model−Wide Utilities Library

    10−8  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 10.7. Updated model for Example 10.3

    10.2.2 The Doc Text Block

    The Doc Text block or DocBlock allows us to create and edit text that documents a model andsave that text with the model. To create a file that contains relevant text, we double−click on thisblock to open the file in the text editor that we have selected in the MATLAB Preferences dialogbox. We use the text editor to modify the text and save the file. Simulink stores the contents of the saved file in the model file block.

     Example 10.4

    In Figure 10.8 the DOC Text block is provided to justify the necessity for the Data Type Conver-sion block. Let us insert appropriate text for justification.

    We double-click on the DOC Text block and in the Text Editor we replace the displayed messagewith the following text:

    The Convert block was inserted to convert the Boolean output of theCheck Dynamic Gap to double as required by the Bus Creator block.

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    9/11

    Introduction to Simulink with Engineering Applications 10−9Copyright © Orchard Publications

    The Modeling Guides Sub−Library

    Figure 10.8. Model for Example 10.4

    This message will be displayed on MATLAB’s Editor whenever we double click on the Doc Textblock in the model of Figure 10.8.

    10.3 The Modeling Guides Sub−LibraryThe Modeling Guides Sub-Library contains only the Block Support Table which is describedbelow.

    The Block Support Table block includes a table which describes the data types that are sup-ported by blocks in the main Simulink library. All blocks that can generate code contain an "X" in

    the column titled "Code Generation Support". A subset of these blocks is not recommended forproduction code as flagged by Note N6. Guidelines to determine when a block is recommendedfor production code are listed below the table. Some blocks include caveats and notes that shouldbe taken into account when they are used. Caveats and notes are indicated in the table by "C#"and "N#", respectively, and are described below the table.

     Example 10.5

    For the model of Figure 10.9, we will determine the types of data the Clock, Signal Generator, andthe Scope blocks will accept.

    Figure 10.9. Model for Example 10.5

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    10/11

    Chapter 10 The Model−Wide Utilities Library

    10−10  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    We double−click on the Block Support Table block and from the table displayed we find that theClock and Signal Generator blocks will accept the double data type but as noted by Note N6 nei-ther is recommended for production code. The Scope block will accept all data types listed in thetable.

  • 8/9/2019 BAB10 - The Model-Wide Utilities Library

    11/11

    Introduction to Simulink with Engineering Applications 10−11Copyright © Orchard Publications

    Summary

    10.4 Summary

    • The Trigger− Based Linearization block, when triggered, invokes the MATLAB commandlinmod or dlinmod to create a linear model for the system.

    • The Time− Based Linearization block invokes the MATLAB command linmod or dlinmod

    to create a linear model for the system when the simulation clock reaches the time specified bythe Linearization time parameter.

    • The Model Info block The Model Info block displays revision control information about amodel as an annotation block in the model's block diagram.

    • The Doc Text block or DocBlock allows us to create and edit text that documents a modeland save that text with the model.

    • The Block Support Table block describes the data types that are supported by blocks in themain Simulink library.