Main Content

Access Data from Model Outputs in Fault Behaviors

Since R2024b

If you want to inject faults into your Simulink® or System Composer™ models, you must model the behavior that each fault introduces. By default, the fault behavior assigned to a fault retrieves data only from the signal that has the fault. If you want to use model data from other signals in your fault behavior, use Fault Data Inport blocks. Fault Data Inport blocks map to data from output ports and feed the data to the Fault Subsystem block that models the fault behavior. You can configure Fault Data Inport blocks interactively or programmatically.

For more information on creating faults and fault behaviors, see Define and Model Faults and Create Predefined and Custom Fault Behaviors.

Add Fault Data Inport Blocks to Fault Behaviors

You can add a Fault Data Inport block when you create a fault behavior or manually add a Fault Data Inport block to an existing fault behavior. You can only add Fault Data Inport blocks to the top level of the Fault Subsystem block.

Create New Faults that have Behavior that Contain a Fault Data Inport block

To create a new fault that contains a Fault Data Inport block in its fault behavior:

  1. Open the Fault Analyzer app. In the Apps tab, click Fault Analyzer.

  2. Select a Simulink model signal.

  3. In the Fault Analyzer tab, click Add Fault.

  4. In the Add Fault window, enable the Add fault behavior property.

  5. Set the Fault library property to mwfaultlib, set the Fault behavior property to Custom fault behavior, and enable the Add Fault Data Inport block to behavior property.

    A section of the Add fault window. The section lists five properties. At the top, the Add fault behavior property is selected. below that are the Fault library and Fault behavior properties. The Fault library property is mwfaultlib, and the Fault behavior property is set to Custom fault behavior. Below these properties is the Add Fault Data Inport block behavior property, and it is selected.

  6. Click OK.

The Fault Subsystem block that models the fault behavior contains a Fault Data Inport, Fault Inport, and Fault Outport block.

This shows the Fault Subsystem block if you select custom fault behavior and enable. The behavior has three unconnected blocks. A Fault Inport and Fault Data Inport block are on the left, and a Fault Outport block is on the right.

Add Fault Behavior that Contains a Fault Data Inport Block to Existing Faults

To add fault behavior that contains a Fault Data Inport block to an existing fault:

  1. In the model, click the fault badge of a fault that does not have behavior.

  2. Click the Add fault behavior icon in the preview window. The Add Fault Behavior window opens.

  3. Set the Fault library property to mwfaultlib, set the Fault behavior property to Custom fault behavior, and enable the Add Fault Data Inport block to behavior property.

  4. Click OK.

The Fault Subsystem block that models the fault behavior contains a Fault Data Inport block, a Fault Inport block, and a Fault Outport block.

Add Fault Data Inport Blocks to Existing Fault Behavior

To add a Fault Data Inport block to existing fault behaviors:

  1. Open the fault behavior. In the model with the fault, click the fault badge of a fault that has behavior.

  2. Click the fault behavior preview window. When the fault model is not loaded, the preview window displays the Open fault behavior icon for each fault behavior.

  3. In the Fault Subsystem block that models the behavior, add the Fault Data Inport block. Open the Library Browser, expand Simulink Fault Analyzer > Fault Port Blocks, and add the block to the model.

You can add more than one Fault Data Inport block to each Fault Subsystem block.

You can add Fault Data Inport blocks to fault behaviors in custom libraries. For more information, see Customize Fault Behaviors by Using Libraries. You must assign the behavior to a fault before you map the block to a signal.

You can also add Fault Data Inport blocks to fault behaviors of faults in referenced models. For more information, Manage Faults in Referenced Models. If you add a fault to a referenced model that is open as a standalone model, you cannot map the Fault Data Inport block to the model that contains the referenced model.

Retrieve Model Data

After adding the Fault Data Inport block to a fault behavior, you must map the block to an output port in the model. To map data to an output port:

  1. Double-click the Fault Data Inport block. The Property Inspector opens and lists the Fault Data Inport blocks in the subsystem.

  2. In the Fault Data Inport Blocks section, click Map to Model Elements. The model that contains the fault opens in bind mode.

  3. Select an output port to map to the block. Click a signal and select an output port.

  4. Exit bind mode.

You can also map the block to output ports by using the action bar. Point to the Fault Data Inport block, then point to the ellipsis above the block to open the action bar. Click the connect icon to open the model in bind mode.

The Fault Data Inport Blocks section lists the output port mapped to each Fault Data Import block. Click the data source to highlight the location in the model.

Programmatically Configure Fault Data Inport Blocks

To programmatically create and connect the block to data:

  1. Add the Fault Data Inport block to the fault behavior by using the add_block function.

  2. Map the block to the signal by using the Simulink.fault.dataInportSource function.

Example Fault Behavior with a Fault Data Inport Block

This example shows how to use model data in a fault behavior by using a Fault Data Inport block. The Fault Data Inport block retrieves data from an output port from a block in the model and sends it to the fault behavior.

Inspect the Model

Open the model. The model contains three signal sources: a Pulse Generator block, a Sine Wave block, and a Constant block. The model has one fault on the output port of the Sine Wave block.

View the Fault Behavior

Open the fault behavior. In the model, click the fault badge, then click the fault behavior preview window. When the fault triggers, the behavior adds the data from the Fault Data Inport block to the signal.

Double-click the Fault Data Inport block to open the Property Inspector. The Property Inspector lists the Fault Data Inport block name and the path of the model element in the Fault Data Inport Blocks section. In this example, the Fault Data Inport block retrieves the data from the output of the Pulse Generator block. The Property Inspector also lists other properties, including the trigger time. The fault triggers when the simulation time is 5.

In the Fault Data Inport Blocks section, click the model element to highlight the data source location in the model.

Simulate the Model

Run the model to view the results. The Scope block indicates that the data from the Pulse Generator block applies to the fault behavior after 5 seconds.

See Also

|

Related Topics