Main Content

Conditionally Execute Referenced Models

Aconditionally executed referenced model, orconditional model, allows you to control its execution with an external signal. The external signal, called the控制信号, is attached to thecontrol input port. Conditional models are useful when you create complex model hierarchies that contain components whose execution depends on other components.

Conditional Models

You can set up referenced models to execute conditionally, similar to conditional subsystems. For information about conditional subsystems, seeConditionally Executed Subsystems Overview.

金宝app®software supports these conditional model types:

Conditional Model Description
Enabled

An enable port executes a referenced model at each simulation step for which the control signal has a positive value. To add an enable port to aModelblock, insert anEnableblock in the referenced model.

This image displays the contents of a simple enabled referenced model.

For an example of an enabledsubsystem, seeEnabled Subsystems. A corresponding enabled referenced model uses the same blocks as are in the enabled subsystem.

Triggered

A trigger port executes a referenced model each time a trigger event occurs. To add a trigger port to aModelblock, insert aTriggerblock in the referenced model.

This image displays the contents of a simple triggered referenced model.

For an example of a triggered model, seeIntroduction to Managing Data with Model Reference.

Triggered and Enabled

AModelblock can have both trigger and enable ports. If the enable control signal has a positive value at the time step for which a trigger event occurs, a triggered and enabled model executes once.

函数调用

A function-call port executes a referenced model each time a function-call event occurs. To add a function-call port to aModelblock, insert aTriggerblock in the referenced model. Then, open the Block Parameters dialog box and set theTrigger typetofunction-call.

A Stateflow®chart, a函数调用Generatorblock, aHit Crossingblock, or an appropriately configured custom S-function can provide function-call events. SeeUsing Function-Call Subsystems.

This image displays the contents of a simple function-call referenced model.

For an example of a function-call model, seeModel Reference Function-Call.

Requirements for Conditional Models

Conditional models must meet the requirements for:

Conditional models must also meet the requirements specific to each type of conditional model.

Conditional Model Requirements
Enabled
  • Multi-rate enabled models cannot use multi-tasking solvers. Use single-tasking.

  • For models with enable ports at the root, if the model uses a fixed-step solver, the fixed-step size of the model must not exceed the rate for any block in the model.

  • Signal attributes of the enable port in the referenced model must be consistent with the input that theModelblock provides to that enable port.

Triggered

Signal attributes of the trigger port in the referenced model must be consistent with the input that theModelblock provides to that trigger port.

Triggered and Enabled See requirements for triggered models and enabled models.
函数调用
  • A function-call model cannot have an output port driven only byGroundblocks, including hiddenGroundblocks inserted by Simulink. To meet this requirement, do the following:

    1. Insert aSignal Conversionblock into the signal connected to the output port.

    2. Enable theExclude this block from 'Block reduction' optimizationoption of the inserted block.

  • The parent model must trigger the function-call model at the rate specified by theConfiguration Parameters>Solver'Fixed-step size'option if the function-call model meets both these conditions:

    • It specifies a fixed-step solver.

    • It contains one or more blocks that use absolute or elapsed time.

    Otherwise, the parent model can trigger the function-call model at any rate.

  • A function-call model must not have direct internal connections between its root-level input and output ports. Simulink does not honor theNoneandWarningsettings for theInvalid root Inport/Outport block connectiondiagnostic for a referenced function-call model. It reports all invalid root port connections as errors.

  • If theSample time typeperiodic, the sample-time period must not contain an offset.

  • The signal connected to a function-call port of aModelblock must be scalar.

Modify a Referenced Model for Conditional Execution

  1. At the root level of the referenced model, insert one of the following blocks:

    Type of Model Blocks to Insert

    Enabled

    Enable

    Triggered

    Trigger

    Triggered and Enabled

    Trigger and Enable

    函数调用

    Trigger

    For an enabled model, go to Step 3.

  2. For theTriggerblock, set theTrigger typeparameter:

    Type of Model Trigger Type Parameter Setting

    Triggered

    Triggered and enabled

    One of the following:

    • rising

    • falling

    • either

    函数调用

    function-call

  3. Use theModelblock ports to connect the referenced model to other ports in the parent model.

    • 的顶部Modelblock displays an icon that corresponds to the control signal type expected by the referenced model. For a triggered model, the top of theModelblock displays this icon.

See Also

Blocks

Related Topics