Main Content

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

This example shows how to control the active choice of a Variant Subsystem that 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, see Variant Subsystems.

Model

Open the slexVariantSubsystemUsingMaskAndEnums model.

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 parameter engine. During simulation, the value of engine is used to evaluate the variant condition expressions to activate or deactivate the underlying Turbo Engine and Non Turbo Engine subsystems.

  • Fidelity type for turbo engine: This parameter becomes available only if the Engine type parameter is set to Turbo. 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 parameter enginetype of the Turbo Engine subsystem. During simulation, the value of enginetype is 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 the Engine type parameter is set to Non 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 parameter enginetype of the Non Turbo Engine subsystem. During simulation, the value of enginetype is used to evaluate the variant condition expression to activate or deactivate the underlying High, Medium, and Low subsystems.

The scope of enginetype in the Turbo Engine subsystem is different from the scope of enginetype in the Non Turbo Engine subsystem. enginetype of Turbo Engine is visible only to the underlying layers of the Turbo Engine subsystem. Similarly, enginetype of Non Turbo Engine is visible only to the underlying 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 the Simulation tab, click Run. On the mask dialog of the Engine subsystem, the Engine type parameter is set to Non Turbo, and the Fidelity type for non turbo engine is set to Medium. As these parameters are mapped to the index of the mask parameters engine and engineType, the value of engine is set to 2, and the value of engineType is set to 1. Here, 2 specifies the index of the Non Turbo option, and 1 specifies the index of the High option.

    During simulation, the condition expressions engine == Engine.NONTURBO and engineType == EngineFidelity.MEDIUM evaluate to true. Here, Engine and EngineFidelity are integer-based enumeration classes defined in Engine.m and EngineFidelity.m files.

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

  2. To modify the active choice, select Turbo in the mask dialog box, then simulate the model again. During simulation, the value of engine is set to 1, which evaluates the variant condition engine == Engine.TURBO to true. The Turbo Engine subsystem becomes active, and the Non Turbo Engine subsystem becomes inactive.

Related Topics