Simulink SubSystems and Masking April 22, Copyright , Andy Packard. This work is licensed under the Creative Commons Attribution- ShareAlike License. To view a copy of this license, visit sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. sa/2.0/
A (very simplified) car model Consider a very simplified car model, modeling 1-dimensional motion on a straight (but perhaps hilly) road. Writing down Newton’s law, assuming a simple proportionality model for Engine force (from throttle angle) and resistance (from speed) would give the differential equation model as Throttle angle u Disturbance force d Simple model of car’s behavior Speed v Engine effectiveness Car mass Resistance factor acceleration throttle angle speed Disturbance force
Simple car model in Simulink For Simulink, we rewrite the original equation as and draw it using –Summing junctions –Gains –Integrator –InPorts, OutPorts
Simple car model in Simulink Goal: Treat this as one entity, a “car”, with 4 parameters –Initial speed (v(0)) –Engine Effectiveness (E) –Drag Coefficient (α) –Mass (m) but, as shown, it is really many blocks. And, the parameters are all in different blocks. Two features to alleviate this: –Subsystems Group blocks (the constituent elements) into a single block (the subsystem) –Masks Create a new dialog box (the Mask Dialog) for a subsystem Actual dialog entries of constituent elements are dependent on the dialog entries of the new dialog
Creating a subsystem Within a model… Click and drag to select the blocks that will constitute the subsystem… They become selected… Choose “Create Subsystem” from “Edit” menu… Mission Accomplished
Opening a subsystem You can drill back down into a subsystem by double-clicking… But, to enter any values (mass, drag, engine effectiveness, etc), you have to open each block, and individually enter. For example, double-click on the 1/Mass gain block… Another window opens, with all the details as before (now there are input and output ports too)… So, to the user, although the subsystem groups the blocks together, the 4 “properties” are still in separate places. Still need something else. Masks.
Component parameters from Mask Variables Open each block, and enter a descriptive variable name in the appropriate parameter dialog box
Creating and Editing the Mask Select the Subsystem (single click) Choose “Mask Subsystem” from “Edit” The Mask Editor opens. This pane is for customizing the appearance of the block’s icon. We will not cover this here. Click on the Parameters pane selector. That will be used to create the Dialog Box for the subsystem.
Mask Parameters This pane defines the dialog box that user’s will interact with after double-clicking the block. We need to create 4 parameters. We will use editable text (as opposed to popups, etc) Click Add button Enter a Prompt, and a Variable Name. The expression that the user types in the dialog box will be evaluated, and a variable (of the defined name) will be created with that value Add as many as you need Rearrange/Remove with tools
Mask Initialization Enter code that must be run to convert the Mask Dialog Variables into the variable names that are entered in the dialog boxes of the blocks that make up the subsystem (the gain blocks, and the integrator). Could also do a lot of error checking…
What happens during Mask Initialization When you start a simulation, initialization processes are carried out. For a Mask, this entails: –Evaluate expressions in the MaskDialog box expressions in Dialog Boxes are evaluated in Base Workspace, unless otherwise specified by SrcWorkspace option in simset –Assign the resulting values to the Mask Dialog Variables (which “live” in the Mask Workspace of the block) –Execute the Mask Initialization Code in the Mask Workspace, creating more variables in Mask Workspace. At this point, the Mask Workspace consists of –the Mask Dialog Variables, and –any variables defined by the Mask Initialization Code. Then, the dialog boxes of the underlying blocks in the masked subsystem are evaluated. These are evaluated in the Mask Workspace, so that all Mask Variables are visible.
Mask Documentation The Documentation pane is where descriptive narrative is entered, as well as HTML code for the block “help”. Let’s just enter some text, and see what effect it has…
Masked subsystem’s behavior After masking, it simply opens the Mask Dialog box, as we have designed it Before masking the subsystem, double- clicking on the subsubsystem revealed the internal structure of the subsystem.
Clean things up… Now close that, and things are starting to look pretty professional. Select the subsystem, and choose “Look Under Mask” from “edit” to get back to the actual underlying structure. Edit the names of the input and output ports.
Make a Library Choose “File->New->Library” from any Simulink window. Repeat. Add more blocks to Library.