Model Variants in a Mechanical System Using Variant Connector Blocks
This example shows how to simulate the displacement of velocity sources and mass for different variant configurations using leaf type Variant Connector blocks. Variant Connector blocks allow you to activate or deactivate a set of components in the network during simulation without having to physically remove the components or exclude them from simulation.
Explore the Model
To open the Variant Leaf Region in Mechanical System example model, at the MATLAB® command prompt, enter
openExample('simscape/VariantLeafRegionInMechanicalSystemExample')
.
This model has two Variant Connector blocks, VC_1 and VC_2. These are leaf type Variant
Connector blocks. VC_1 has the variant condition A == 1
and VC_2 has the
variant condition B == 1
.
During simulation, Simulink® computes the variant conditions associated with each leaf type Variant
Connector block. If the variant condition of a Variant Connector block evaluates to
true
, all the physical components that are inside the leaf region of
that block become active. For example, if A == 1
evaluates to
true
, the components inside LeafRegion_1 become active. If A
== 1
evaluates to false
, the components inside LeafRegion_1
remain inactive.
Simulate the Mechanical System for Different Variant Configurations
The variant condition variables, A
and B
, are
defined in the PostLoadFcn
callback. To view or modify the value of these
variables on the Modeling tab, select Model Settings > Model Properties. On the Callbacks tab, in the Model
callbacks pane, click PostLoadFcn. In this example, the
value of A = 1
and B = 2
. The associated leaf region
activates based on these variables.
Case 1: LeafRegion_1 Is Active and LeafRegion_2 Is Inactive
In the Model Properties window, set the value of
A
to1
andB
to2
.Click Run and see the variant conditions propagate from the Variant Connector blocks to the connected components.
To analyze the propagated variant conditions and the block activation state, on the Debug tab, select Information Overlays > Variant Legend. For more information on Variant Condition Legend, see Visualize Propagated Variant Conditions in Variant Conditions Legend.
A == 1
evaluates totrue
. The components inside LeafRegion_1 become active.B == 1
evaluates tofalse
. The components inside LeafRegion_2 become inactive.
View the displacement of mass and the velocity source by clicking the Plot link in the Variant Leaf Region in Mechanical System table that corresponds to the condition,
A == 1
istrue
andB == 1
isfalse
.
Case 2: LeafRegion_1 Is Inactive and LeafRegion_2 Is Active
In the Model Properties window, set the value of
A
to1
andB
to2
, and then simulate the model.Analyze the variant conditions and the block activation state.
A == 1
evaluates tofalse
. The components inside LeafRegion_1 become inactive.B == 1
evaluates totrue
. The components inside LeafRegion_2 become active
View the displacement of mass and the velocity source by clicking the Plot link in the Variant Leaf Region in Mechanical System table that corresponds to the condition,
A==1
isfalse
andB==1
istrue
.
Similarly, you can set the value of A
and B
to
0
and analyze how both the regions become inactive during
simulation.