Contenuto principale

Define Variant Configurations for the Model

R2026b

Defining a variant configuration lets you represent a specific design alternative that you implemented in the Simulink® model using variant elements (variant blocks, variant parameters, variant transitions). You set up the configuration by combining variant choices across your model hierarchy.

Open Example Model

Open the VMControllerGS model.

modelName = "VMControllerGS";
open_system(modelName);

Explore Model

The controller in the VMControllerGS model can operate in one of three modes: Linear, Nonlinear, or Smart. Each mode corresponds to a different variant configuration. You can also define configurations that span the model hierarchy. For instance, you might set up a configuration where the controller runs in Linear mode while the plant operates in Trial mode. In Variant Manager, you define a variant configuration as a set of variant control variables and their values that activates a specific variant path in your model hierarchy.

The VMControllerGS model does not have any variant configurations defined. Follow these steps to create some configurations for the model.

Add Variant Configurations Object for Model

Create a Simulink.VariantConfigurations object to store your variant configurations.

  1. In Variant Manager, in the toolstrip, enter a name for the object in the Name box.

    Variant Manager toolstrip shows the name of the variant configurations object in the Simulink.VariantConfigurations text box.

  2. Click Apply Changes to associate the model to the variant configurations object, which is added in the data dictionary, dVMControllerGS.sldd. Variant Manager identifies and populates the name of the data source in the Source box.

  3. Save the model and the data dictionary.

Set Up Variant Control Variables Manually

Variant control variables can be automatically identified or set up manually. Automatic identification (importing variant control variables) is generally easier and less error-prone than setting up variant control variables manually.

Create a configuration for a nonlinear controller with low-fidelity parameter value settings.

  1. In the Configurations pane, click the Add variant configuration button . A new row appears in the configurations table. Give your configuration a name, such as NonlinearLowFid.

    Configurations pane shows the newly added configuration.

  2. Identify the variant control variables needed to activate the Nonlinear Controller component with low-fidelity variant parameter values.

    Use the Blocks and Variant Parameters tabs to find which variant control variables are used in the variant condition expressions.

    For this example, you need:

    • vCtrl (for the controller type)

    • vLUTFid (for fidelity level)

  3. In the Control Variables section, click the Add control variable button , and then start typing the variable name in the Name column of the table. Variant Manager suggests matching variables from the data sources of the model. Select vCtrl. Variant Manager autofills the value ControllerTypesGS.Linear from the data source. Change the value to ControllerTypesGS.Nonlinear.

    In the Control Variables section, the Name field lists the control variable that matches the typed value.

  4. Repeat the previous step for vLUTFid, selecting the appropriate value for high fidelity.

    Control variables table shows the two control variables that were manually added to the configuration.

    Tip

    You can also manually copy the variable name and value from the variant condition expression in the model hierarchy table instead of typing them.

    You can toggle the visibility of the Variant Activation Time and Source columns in the table using the button.

    Optionally, add a description to help others understand the purpose and details of this configuration.

    Control Variables table shows the manually set up variables and the description.

  5. All rows in the model hierarchy table appear dimmed for the newly added configuration because the configuration has not been applied to the model. In the Variant Manager toolstrip, click Activate Configuration. The operation checks that the variant configuration is set up correctly and applies the configuration to the model.

    In the Blocks tab, the Nonlinear Controller is active.

    Blocks tab in Variant Manager shows the Nonlinear Controller as the active choice in the model hierarchy pane.

    In the Variant Parameters tab, the low-fidelity choice of the variant parameters pLUTBPs and pLUTData are active. The default choice of parameters pInitCond and pKc are active because they do not have a specific value defined for the condition vCtrl == ControllerTypesGS.Nonlinear.

    You can verify the control variable values in dVMControllerGS.sldd. When you activate the configuration, the software writes the values back to the data source automatically.

  6. Simulate the model and verify that the model simulates with the active configuration.

    After simulation of the VMControllerGS model, the Controller variant subsystem shows Nonlinear Controller as the active choice.

Import Control Variables Automatically

Importing variant control variables is a quick and reliable way to define configurations, especially when your model is already set up with the right variant controls. This operation imports all variant control variables used across a model hierarchy to the configuration.

Create a configuration for a nonlinear controller with high-fidelity parameter value settings.

  1. Add a new configuration and name it NonlinearHighFid.

  2. Click Import control variables across model hierarchy . Variant Manager imports the variant control variables used by variant elements in the model from the data sources where they are defined.

  3. Update the control variable values:

    • Set vCtrl to ControllerTypesGS.Nonlinear.

    • Set vLUTFid to LUTFidelityModesGS.High.

  4. Activate the configuration.

    Control variables table shows variables added using the import option.

Copy an Existing Configuration

Create a configuration for a linear controller.

  1. In the Configurations table, right-click the NonLinearLowFid configuration or click the Open context menu button , and select Copy. The configuration is copied with a new name.

    Tip

    You can select multiple configurations or constraints simultaneously for bulk operations such as copy or delete. Hold down the Shift key as you click each row that you want to include in the multi-selection.

    Configurations pane shows the copy option in the context menu and shows the copied configuration.

  2. Rename the new configuration to Linear.

  3. Update the control variable values:

    Set vCtrl to ControllerTypesGS.Linear.

    Set vLUTFid to LUTFidelityModesGS.Low.

  4. Activate the new configuration.

Save the configurations. See Save Variant Configurations.

Open Completed Model

You can also access a fully set-up version of the models used in this tutorial, which already includes all configurations. To open this version, use this command.

open_system("slexVariantManagerOverview");

See Also

|

Topics