Create Predefined and Custom Fault Behaviors
Fault behaviors are the behaviors you assign to the faults into your model. You can use predefined or custom fault behaviors by modeling the behavior inside a Fault Subsystem block. If you want to reuse your custom fault behaviors, you can create libraries to store the new behaviors.
Add Predefined Fault Behaviors
You can assign fault behaviors to faults when you create them or add them to existing
Fault Analyzer™ comes with a built-in list of example fault behaviors that you can select and
stores the predefined behaviors in a library file,
mwfaultlib.slx. You can
use these fault behaviors as-is for scalar double signals.
Inspect the Default Fault Behavior Library
To open the library that stores the predefined fault behaviors, navigate to
\matlab\toolbox\safety\block_libraries and open the default fault
You cannot modify this library.
Add Built-In Behaviors to Faults
To create a fault and assign fault behavior to it:
Select the signal.
In the Apps tab, select Fault Analyzer.
In the Fault Analyzer tab, in the Prepare Faults section, click Add Fault. The Create Fault window opens.
Select Add fault behavior.
Set the Fault library property to
Select the fault behavior from the Fault behavior property and click OK.
To add behavior to existing faults that do not have assigned behavior:
Click the fault badge where the fault is added.
Click the Add fault behavior icon in the preview window. The Add Fault Behavior window opens.
In the Add Fault Behavior window, set the Fault library property to
mwfaultliband select the fault behavior from the Fault behavior property. Click OK.
You can also create fault behaviors from the Fault Table pane:
Open the Fault Table pane. In the Fault Analyzer tab, in the View section, click Fault Table.
Right-click the fault and click Properties.
In the Property Inspector, click Add fault behavior.
You cannot add fault behavior to a fault that already has fault behavior.
Open Assigned Fault Behaviors
When you add fault behavior to a fault, a Fault Subsystem block contains the assigned fault behavior. These blocks are stored in a model called the fault model. To view the assigned fault behaviors, open the fault model by using one of these approaches:
Click the fault badge , then 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.
Open the Fault Table pane. Expand the model elements in the Name column to see the faults. Right-click the fault and select Open fault behavior.
For example, add a fault to a model, use the built-in library, and set Select
fault behavior to
Add Noise. This fault behavior
adds noise to the signal. Open the Fault Subsystem block to inspect the
blocks that model the fault behavior. Fault Subsystem blocks include one
Fault Inport and Fault Outport block that indicate where the
signal enters and exits the subsystem, respectively.
After creating a behavior, you can modify the blocks in the subsystem. If you set
Fault behavior to
Custom fault behavior,
the Fault Subsystem block contains only the Fault Inport and
Fault Outport blocks.
You must add blocks and signals to model the custom behavior.
Fault Subsystem blocks associated with faults on block input or output ports must have only one Fault Input and one Fault Outport block.
Trace Fault Behaviors to Assigned Faults
You can trace fault behaviors to their assigned faults. When you trace fault behaviors, the model highlights the associated model element and affected signals.
To trace fault behavior, use one of these approaches:
In the fault model, click the Fault Subsystem block. In the Fault Subsystem tab, in the Fault section, click Trace to Fault Source.
Open the Fault Subsystem block. Select either the Fault Inport or Fault Outport block. In the Fault Port tab, in the Fault section, click Trace to Fault Source.
In the fault model, on the block mask of a Fault Subsystem block, double-click the Fault properties button . In the Property Inspector, click Trace to Fault Source.
Multiple models can use the same fault model. To trace fault behaviors from a different model, load each model that contains the faults.
Customize Fault Behaviors by Using Libraries
The Fault behavior property lists the fault behaviors in the library you select. This list depends the library you select in the Fault library property. If you want to create a new list in the Select fault behavior property, you must create a new library.
If you assign a behavior to a fault from the default library, Simulink Fault Analyzer creates a copy of the subsystem in the fault model that you can modify. If you assign behavior from a custom library, Simulink Fault Analyzer creates a linked copy of the subsystem in the fault model that you can only modify in the custom library.
Register Custom Fault Behaviors with Functions
To add custom fault behaviors to the Fault behavior property, create a custom library and register the fault behaviors:
Create an empty Simulink model or library and save it on the path.
In the library or model, add a Fault Subsystem block from the Simulink Fault Analyzer library. Only include Fault Subsystem blocks. Once you add a Fault Subsystem block, you cannot open Simulink Fault Analyzer.
Open the Fault Subsystem block. Add blocks that model your desired fault behavior. Connect the blocks to the Fault Inport and Fault Outport blocks.
Save the library.
Simulink.fault.librariesfunction to register the library. For example, to register a library in the working folder named
myLibrary, enter this command in the Command Window:
The name you assign to each Fault Subsystem block in the custom library is the name that appears in the Fault behavior property. To ensure compatibility, use the allowable characters for subsystem names. See jc_0231: Usable characters for block names and jc_0243: Length restriction for subsystem names.
After creating the custom library, you can export it like any other library file. You can copy the library to a directory on the path for other users.
To unregister the custom library, use the
Register Libraries with
You can also register custom libraries by using an
sl_customization function runs when you load MATLAB® or enter
sl_refresh_customizations in the Command Window.
For more information, see Register Customizations with Simulink. To register custom libraries with
sl_customization, save the library and create an
sl_customization.m file on the same path. For example, to register a
customFaultLib, create a function named
sl_customization.m that includes this code:
function sl_customization(cm) cObj = cm.SimulinkFaultCustomizer; cObj.clearCustomFaultLibraries; cObj.addCustomFaultLibrary("customFaultLib");
In this example, the code unregisters the custom libraries with the
clearCustomFaultLibraries function, and then registers the
customFaultLib library with
function. The input argument of
addCustomFaultLibrary must be a string
scalar or character vector that contains the name of your library.
You can copy the library and
sl_customization.m to a directory on the
path for other users. To unregister specific libraries, use the
removeCustomFaultLibrary function. For example, to unregister
customFaultLib, enter this code into the
function sl_customization(cm) cObj = cm.SimulinkFaultCustomizer; cObj.removeCustomFaultLibrary("customFaultLib");