Main Content

Control Active Choice of Locked Custom Library Variant Subsystem Using Mask Parameter

This example shows how to control the active choice of aVariant Subsystemthat belongs to a locked custom library by using a mask parameter as Variant control variable. Mask parameters limit the scope of the variable, which allows you to use the same names for control variables in different scopes. This example includes promoted parameters and control expressions with enumeration classes to simplify the interface of the mask dialog and control expressions with enumeration classes to improve the readability of the variant condition expressions. For more information on Variant Subsystems, seeVariant Subsystems.

Model

To open the Simulink®model, typeslexVariantSubsystemUsingMaskAndEnumsin the MATLAB®Command Window.

Consider the Engine subsystem block in the locked custom library,slexVarEngineLibrary.

The mask dialog box of the subsystem contains these parameters:

  • Engine type: When you select a value for this parameter, Simulink assigns the index of that value to the mask parameterengine. During simulation, the value ofengineis used to evaluate the variant condition expressions to activate or deactivate the underlying Turbo Engine and Non Turbo Engine subsystems.

  • 忠诚型涡轮增压发动机: This parameter becomes available only if theEngine typeparameter is set toTurbo. This parameter is promoted on to the mask dialog of the Engine subsystem from the underlying layer of the Turbo Engine subsystem. When you select a value for this parameter, Simulink assigns the index of that value to the mask parameterenginetypeof the Turbo Engine subsystem. During simulation, the value ofenginetypeis used to evaluate the variant condition expression to activate or deactivate the underlying High, Medium, and Low subsystems.

  • Fidelity type for non turbo engine: This parameter becomes available only if theEngine typeparameter is set toNon Turbo. This parameter is promoted on to the mask dialog of the Engine subsystem from the underlying layer of the Non Turbo Engine subsystem. When you select a value for this parameter, Simulink assigns the index of that value to the mask parameterenginetypeof the Non Turbo Engine subsystem. During simulation, the value ofenginetypeis used to evaluate the variant condition expression to activate or deactivate the underlying High, Medium, and Low subsystems.

The scope ofenginetypein the Turbo Engine subsystem is different from the scope ofenginetypein the Non Turbo Engine subsystem.enginetypeof Turbo Engine is visible only to the underlying layers of the Turbo Engine subsystem. Similarly,enginetype非涡轮增压发动机是可见的只有基石ing layers of the Non Turbo Engine subsystem. Limiting the scope by using mask parameters as Variant control variables allows you to use the same name for variables with holding different values in the Turbo Engine and the Non Turbo Engine subsystems.

Switch Between Active Choices

  1. To simulate the model, on theSimulationtab, click Run. On the mask dialog of the Engine subsystem, theEngine typeparameter is set toNon Turbo, and theFidelity type for non turbo engineis set toMedium. As these parameters are mapped to the index of the mask parametersengineandengineType, the value ofengineis set to2, and the value ofengineTypeis set to1. Here,2specifies the index of theNon Turbooption, and1specifies the index of theHighoption. For more information on how the parameters on the mask dialog box are mapped to the underlying mask parameters, seeCreate a Simple Mask.

    During simulation, the condition expressionsengine == Engine.NONTURBOandengineType == EngineFidelity.MEDIUMevaluate totrue. Here,EngineandEngineFidelityare integer-based enumeration classes defined inEngine.mandEngineFidelity.mfiles with values forEngine.TURBOandEngine.NONTURBOspecified as1and2, and the values forEngineFidelity.HIGH,EngineFidelity.MEDIUM, andEngineFidelity.LOWspecified as1,2, and3.

    The NonTurbo Engine subsystem becomes active and the Turbo Engine subsystem becomes inactive.

  2. To modify the active choice, selectTurboin the mask dialog box, then simulate the model again. During simulation, the value ofengineis set to1, which evaluates the variant conditionengine == Engine.TURBOtotrue. The Turbo Engine subsystem becomes active, and the Non Turbo Engine subsystem becomes inactive.

Related Topics