Change Subsystem Reference Component Dynamically Using Variant Assembly Subsystem
This example shows how you can switch between different subsystem reference components by using a Variant Assembly Subsystem block. A Variant Assembly Subsystem block can use external sources such as subsystem references as variant choices.
The model simulates fog and rain sensor based wipers of a vehicle. Each sensor is modeled using a different subsystem reference component. When you select a specific type of sensor, the model uses a Variant Assembly Subsystem block to switch between the subsystem reference components.
Explore the Model
Open the model slexSubsystemReferenceChoiceUsingVariantAssembly
. The model contains a Sensor-Based Front Wiper
system and a Manually Controlled Rear Wiper
system to control the front and rear wiper speeds during rain or fog.
Sensor-Based Front Wiper System
The front wiper system of the vehicle is sensor-based. It uses either a fog sensor or a rain sensor to get the input voltage signal to calculate the front wiper speed using these components:
Voltage Level Sensor
— TheVoltage Level Sensor
is a Variant Assembly Subsystem block that has fog and rain sensors as the variant choices. The variant choices are stored in the subsystem filesslexFogSensor
andslexRainSensor
, respectively. For information on adding variant choices from subsystem files, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.
To select a specific type of sensor, double-click the Turn on fog sensor
or Turn on rain sensor
Subsystem block in the top left corner of the model. When you select a sensor type, the sensor input variable sensorType
is updated in the model workspace and the variant choice changes to either slexFogSensor
or slexRainSensor
. The selected sensor subsystem then converts the input voltage to a level indicator (low, medium, or high) to feed the Front Wiper Speed Controller.
Front Wiper Speed Controller
— Based on the input level, theFront Wiper Speed Controller
, which references the subsystemslexWiper
, controls the speed of the wiper (cycles per second). To parameterize the low, medium, and high wiper speeds, use the system mask dialog box of theFront Wiper Speed Controller
.
Manually Controlled Rear Wiper System
The speed of the rear wiper of the vehicle is controlled by the driver. Based on the input voltage given by the driver, the Rear Wiper Speed Controller
, which references the subsystem slexWiper
, controls the speed of the rear wiper (cycles per second).
Control the Wipers During Rain
To turn on the wipers during rain, double-click the Turn on rain sensor
component in the top left corner of the model. This sets the sensor input variable sensorType
to choose slexRainSensor
as the sensor component for the front wiper system.
Simulate the model and observe the speed of the front and rear wipers as the sensor voltage and driver input change.