Main Content

Observe Conditional Subsystem Signals

Conditional subsystems are controlled by an external signal that enables or triggers the subsystem. By observing a conditional subsystem, you can check that the subsystem runs only when the controlling signal activates it, and check other functionality in the conditional subsystem. The blocks for which you can add observers are:

  • Enabled Subsystem

  • Triggered Subsystem

  • Enabled and Triggered Subsystem

  • If Action Subsystem

  • Switch Case Action Subsystem

For more information on conditional subsystems, see Conditionally Executed Subsystems Overview.

When you add an observer to a signal in a conditional subsystem, Simulink® adds an Observer Reference block at the top level of the main model and creates an Observer model, which contains an Observer Port block in an aperiodic partition. This partition controls the scheduling of the conditional data. The testing logic in the partition also runs conditionally. Because the partition is created automatically when you create the observer, you do not need to change the partition or scheduling settings. You can change the name of the partition, but the name must be unique within the model.

Add an Observer for a Conditional Subsystem

The steps to add an observer to a conditional subsystem are:

  1. In the conditional subsystem, right-click the signal to observe.

  2. Select Observers > Observe selected signals > New Observer to create an observer for the signal.

    Alternatively, you can select the signal to observe, pause on the ellipsis to open the action bar, then click Observe in New Observer .

    Simulink adds an Observer Reference block to the main model and creates a new Observer model. The new Observer model contains an aperiodic partition that contains an Observer Port block and a Terminator block. For information about partitions, see the "Partitioning a Model" section of Create Partitions

    Aperiodic partition with Observer Port and Terminator blocks.

  3. Replace the Terminator block with a verification block, such as a Test Assessment or Verification Subsystem block and connect the verification block to the Observer Port output. Add logic to verification block to analyze or verify the conditional subsystem signal.

  4. Run the model from the main model, not from the Observer model.

Observe a Signal in a Conditional Subsystem

This example shows how to add an observer for a signal in a conditional subsystem. The ObserveCondSubsys model used in this example contains a sine wave control signal as the input to an Enabled Subsystem block. The Enabled Subsystem block is active only when the sine input is positive.

1. Open the ObserveCondSubsys model.

open_system('ObserveCondSubsys')

Conditional subsystem model with sine input and enabled subsystem block

2. Open the Enabled Subsystem block.

3. Select the Integrator block output signal. Pause on the ellipses to open the action bar, then click Observe in New Observer.

Selected output of Integrator block showing action bar

Simulink adds an Observer Reference block to the top level of the model and opens a new Observer model. This model has an aperiodic partition that contains an Observer Port block with its output connected to a Terminator block.

Top model with added Observer block

Aperiodic partition in Observer model

4. Open the Aperiodic partition by double-clicking it.

5. Replace the Terminator block with a Test Assessment block.

Test assessment block

6. Open the Test Assessment block.

7. Delete step_1_1 and step_1_2.

8. Right-click step_1 and clear the When decomposition check box.

9. In step_1, add verify(data >= 0);

Assessment step verify statement

10. Close the Test Assessment block.

11. Go to the main model and click Run.

12. After the model runs, at the MATLAB command line, use these commands to view the result.

run = Simulink.sdi.Run.getLatest;
dataset = Simulink.sdi.exportRun(run.Id);
assessmentSignalIndices = find(arrayfun(@(idx)...
  isequal(class(dataset{idx}),'sltest.Assessment'),...
  1:dataset.numElements)); 
result = arrayfun(@(idx) dataset{idx}.Result,assessmentSignalIndices)

The verify statement produces a passing result, which indicates that the Enabled Subsystem block and its associated observer are active only when the sine input is positive.

Copyright 2022 The MathWorks, Inc.

Limitations

  • Only one Observer Port can be in an aperiodic partition.

  • Aperiodic partition names must be unique within a model.

  • You cannot edit the scheduling trigger in the aperiodic partition.

  • You cannot drag and drop or reorder items in the Schedule Editor or by using simulink.schedule.OrderedSchedule.

  • You cannot add events to the aperiodic partitions of the Observer model.

  • Partition subsystems and Function-Call Subsystem and For Each Subsystem blocks do not support observers.

See Also

|

Related Topics