Main Content

Control Structural Variations Using Mask Parameters and Model Arguments

This example shows you how to control structural variations using mask parameters and model arguments in a model. You can use mask and model workspace to simulate and generate code for variant blocks with startup activation time.

Model

The models represent a fog lamp controller system that operates in driver switch mode and in Sensor Connected mode. In the Driver Switch mode, the intensity of the fog lamps is controlled by the driver. In Sensor Connected mode, the sensor adjusts the intensity of different types of fog lamps based on the intensity of ambient light in the external environment.

Simulate Using Mask Parameters in Driver Switch and Sensor Connected Modes

The model slexVariantsWithMaskParametersInStartup contains two instances of the Controller variant subsystem block with a mask. The variant control variable CTRL_MODE is defined as a mask parameter. The values of the CTRL_MODE mask parameter in the Controller block mask dialog represent the variant choices which are populated using the enumeration 'InputType' which is available on path.

The Controller variant subsystem in Sensor Connected mode has the condition CTRL_MODE==InputType.Sensor and the Driver Switch mode has the condition CTRL_MODE== InputType.Driver.

In the Driver Switch mode, the LightCommand output is a delayed DriverSwitch signal. This is the equivalent action of the driver manually switching on or off the fog light.

In the sensors connected mode as the active choice, the LightCommand output is high until the SensorOutput is high, independent of the DriverSwitch signal. This is equivalent to sensors overriding the manual switching based on the ambient light.

To simulate, set the activation time of the Controller block to 'startup' and select the active choice from the Block Parameters. Double-click the block parameter mask of the Controller variant subsystem block to select the active choice. Scope shows the Driver Mode output.

sim('slexVariantsWithMaskParametersInStartup');
open_system('slexVariantsWithMaskParametersInStartup/Scope')

Simulate Using Model Arguments in Driver Switch and Sensor Connected Modes

The model slexVariantsWithModelArguments contains two instances of a referenced model, which contains the Variant Subsystem block. The variant control variable CTRL_MODE of the Variant Subsystem block is defined in the model workspace of the referenced model. This model workspace variable is marked as a Model Argument. The model arguments are used as controls for the Variant Subsystem blocks with startup activation time.

To simulate Driver Switch or Sensors Connected mode in Fast restart, change the value of Instance parameter CTRL_MODE of the model reference from the Block Parameters dialog of either the 'Model' or 'Model1' blocks. You can also generate code. The generated code will contain regular if conditions. Scope shows the Driver Mode output of 'Model', and Scope1 shows the Sensor Connected Mode output of 'Model1'.

NOTE : When using the SimulationInput object to create the model workspace variable, the variant control variable must be present in the model workspace.

sim('slexVariantsWithModelArguments');
open_system('slexVariantsWithModelArguments/Scope')