How to Use Variant Subsystem in Simulink?
From the series: Variant Manager
Variant Subsystem enables you to have multiple design variations in a single model. It helps you to easily control the switching between different design choices. This provides flexibility and convenience while modelling components in Simulink. In this video you can learn how to use Variant Subsystems using an example model with multiple controller choices. It includes how you can set-up block parameters for your Variant Subsystem and switch between choices using different variant condition expressions.
Model-Based Design often requires creating multiple design variations for system components to meet different sets of requirements.
To achieve this in Simulink, you can use Variant Subsystem block which allows you to build a single model with multiple design alternatives.
You can create multiple subsystems, model reference, and subsystem reference blocks within a variant subsystem and provide a condition expression for each of them. This feature enables you to select your desired design choice and easily switch between different design options.
For example, consider a Simulink model that controls the output speed of a motor, where You have an option to use multiple controllers, each with their unique control algorithms.
To model variant subsystem, you can click on the canvas and type in Variant Subsystem.
Inside the Variant Subsystem block, you can see two subsystems. You can add more subsystems or models by clicking on the provided link or you can add your existing subsystems directly inside the block.
During model compilation, Simulink will automatically connect the input and output ports to the activated subsystem.
Once the model is built, you must define the block parameters of the Variant Subsystem block.
You'll notice that the block parameter window has already captured the names of the available subsystems.
There are three variant control modes available. In expression mode, you provide an activation condition for each choice. In label mode, you can manually select the active choice and enable sim code gen switching if you want separate choices during model simulation and code generation.
The variant activation time determines at which stage you want to activate your selected variant choice.
In variant Control expression you can mention the condition expressions to control activation of your desired choice.
Here, we have defined simple variable conditions for all choices.
You can also use a direct expression like the one you see on your screen. where Controller is a class name with PI, PD, and PID enumerations. Save this code in a MATLAB file within the same path as that of the model while using such condition expressions.
In this example, we'll use the control variable “Type” to control our selection.
Create a variable called "Type" in the workspace. The value of this variable determines which choice will be executed.
You'll notice that, out of the three subsystems, "PD" is highlighted, and the other two are greyed out. This indicates that the "PD" controller is activated by our control variable.
Also, the name of active subsystem is displayed on the top of the block.
With the selected choice, you can now run your model, and to change your selection, simply modify the value of your control variable which in this case is the “Type” variable.
With this knowledge, you're now equipped to use the Variant Subsystem block to create multiple design variations in a single Simulink model.
To learn more about this block and other Simulink features, check out the resources below and watch our other videos on Variants.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.