This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create Check for Model Configuration Parameters

To verify the configuration parameters for your model, you can create a configuration parameter check.

Decide which configuration parameter settings to use for your model.

GuidelinesSee
MathWorks® Automotive Advisory Board (MAAB) Control Algorithm Modeling GuidelinesMAAB Control Algorithm Modeling (Simulink)
High-Integrity System Modeling GuidelineHigh-Integrity System Modeling (Simulink)

  1. Create an XML data file containing the configuration parameter settings you want to check. You can use Advisor.authoring.generateConfigurationParameterDataFile or manually create the file yourself.

  2. Register the model configuration parameter check using an sl_customization.m file.

  3. Run the check on your models.

Create Data File for Diagnostics Pane Configuration Parameter Check

This example shows how to create a data file for Diagnostics pane model configuration parameter check that warns when:

  • Algebraic loop is set to none

  • Minimize algebraic loop is not set to error

  • Block Priority Violation is not set to error

In the example, to create the data file, you use the Advisor.authoring.generateConfigurationParameterDataFile function.

At the command prompt, type vdp.

In the model window, select Simulation > Model Configuration Parameters. In the Diagnostics pane, set the configuration parameters as follows:

  • Algebraic loop to none

  • Minimize algebraic loop to error

  • Block Priority Violation to error

Use Advisor.authoring.generateConfigurationParameterDataFile to create a data file specifying configuration parameter constraints in the Diagnostics pane. Also, to create a check with a fix action, set FixValue to true. At the command prompt, type:

model='vdp';
dataFileName = 'ex_DataFile.xml';
Advisor.authoring.generateConfigurationParameterDataFile(dataFileName,...
model, 'Pane', 'Diagnostics', 'FixValues', true);

In the Command Window, select ex_DataFile.xml. The data file opens in the MATLAB® editor.

  • The Minimize algebraic loop (command line: ArtificialAlgebraicLoopMsg) configuration parameter tagging specifies a value of error with a fixvalue of error. When you run the configuration parameter check using ex_DataFile.xml, the check fails if the Minimize algebraic loop setting is not error. The check fix action modifies the setting to error.

  • The Block Priority Violation (command line:BlockPriorityViolationMsg) configuration parameter tagging specifies a value of error with a fixvalue of error. When you run the configuration parameter check using ex_DataFile.xml, the check fails if the Block Priority Violation setting is not error. The check fix action modifies the setting to error.

In ex_DataFile.xml, edit the Algebraic loop (command line:AlgebraicLoopMsg) parameter tagging so that the check warns if the value is none. Because you are specifying a configuration parameter that you do not want, you need a NegativeModelParameterConstraint. Also, to create a subcheck that does not have a fix action, remove the line with <fixvalue> tagging. The tagging for the configuration parameter looks as follows:

<!-- Algebraic loop: (AlgebraicLoopMsg)-->
    <NegativeModelParameterConstraint>
        <parameter>AlgebraicLoopMsg</parameter>
        <value>none</value>
    </NegativeModelParameterConstraint>

In ex_DataFile.xml, delete the lines with tagging for configuration parameters that you do not want to check. The data file ex_DataFile.xml provides tagging only for Algebraic loop, Minimize algebraic loop, and Block Priority Violation. For example, ex_DataFile.xml looks similar to:

<?xml version="1.0" encoding="utf-8"?>
<customcheck xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xsi:noNamespaceSchemaLocation="http://www.w3schools.com 
MySchema.xsd">
     <checkdata>       
     <!-- Algebraic loop: (AlgebraicLoopMsg)-->
        <NegativeModelParameterConstraint>
            <parameter>AlgebraicLoopMsg</parameter>
            <value>none</value>
        </NegativeModelParameterConstraint>
    <!--Minimize algebraic loop: (ArtificialAlgebraicLoopMsg)-->
        <PositiveModelParameterConstraint>
            <parameter>ArtificialAlgebraicLoopMsg</parameter>
            <value>error</value>
            <fixvalue>error</fixvalue>    
        </PositiveModelParameterConstraint>
    <!--Block priority violation: (BlockPriorityViolationMsg)-->
        <PositiveModelParameterConstraint>
            <parameter>BlockPriorityViolationMsg</parameter>
            <value>error</value>
            <fixvalue>error</fixvalue>
        </PositiveModelParameterConstraint>
    </checkdata>
</customcheck>

Verify the data syntax with Advisor.authoring.DataFile.validate. At the command prompt, type:

dataFile = 'myDataFile.xml'; 
msg = Advisor.authoring.DataFile.validate(dataFile); 

if isempty(msg)     
    disp('Data file passed the XSD schema validation.'); 
else 
    disp(msg); 
end 

Create Check for Diagnostics Pane Model Configuration Parameters

This example shows how to create a check for Diagnostics pane model configuration parameters using a data file and an sl_customization file. First, you register the check using an sl_customization file. Using ex_DataFile.xml, the check warns when:

  • Algebraic loop is set to none

  • Minimize algebraic loop is not set to error

  • Block Priority Violation is not set to error

The check fix action modifies the Minimize algebraic loop and Block Priority Violation settings to error.

The check uses the ex_DataFile.xml data file created in Create Data File for Diagnostics Pane Configuration Parameter Check.

Close the Model Advisor and your model if either are open.

Use the following sl_customization.m file to specify and register check Example: Check model configuration parameters.

function sl_customization(cm)

% register custom checks.
cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);

% register items to factory group.
cm.addModelAdvisorTaskFcn(@defineModelAdvisorGroups);


%% defineModelAdvisorChecks
function defineModelAdvisorChecks
    
 rec = ModelAdvisor.Check('com.mathworks.Check1');
	rec.Title = 'Example: Check model configuration parameters';
	rec.setCallbackFcn(@(system)(Advisor.authoring.CustomCheck.checkCallback...
                                        (system)), 'None', 'StyleOne');
	rec.TitleTips = 'Example check for model configuration parameters';
	
	% --- data file input parameters
	rec.setInputParametersLayoutGrid([1 1]);
	inputParam1 = ModelAdvisor.InputParameter;
	inputParam1.Name = 'Data File';
	inputParam1.Value = 'ex_DataFile.xml';
	inputParam1.Type = 'String';
	inputParam1.Description = 'Name or full path of XML data file.';
	inputParam1.setRowSpan([1 1]);
	inputParam1.setColSpan([1 1]);
	rec.setInputParameters({inputParam1});

	% -- set fix operation
	act = ModelAdvisor.Action;
	act.setCallbackFcn(@(task)(Advisor.authoring.CustomCheck.actionCallback...
                                                     (task)));
	act.Name = 'Modify Settings';
	act.Description = 'Modify model configuration settings.';
	rec.setAction(act);
    
	mdladvRoot = ModelAdvisor.Root;
	mdladvRoot.register(rec);

%% defineModelAdvisorGroups
function defineModelAdvisorGroups
mdladvRoot = ModelAdvisor.Root;
 
% --- sample factory group 1
rec = ModelAdvisor.FactoryGroup('com.mathworks.Test.factoryGroup');
rec.DisplayName='Example: My Group';
rec.addCheck('com.mathworks.Check1');
mdladvRoot.publish(rec);

Create the Example: Check model configuration parameters. At the command prompt, enter:

Advisor.Manager.refresh_customizations

At the command prompt, type vdp.

In the model window, select Simulation > Model Configuration Parameters. In the Diagnostics pane, to trigger check warnings, set the configuration parameters as follows:

  • Algebraic loop to none

  • Minimize algebraic loop to warning

  • Block Priority Violation to warning

From the model window, select Analysis > Model Advisor > Model Advisor to open the Model Advisor.

In the left pane, select By Task > Example: My Group > Example: Check model configuration parameters. In the right pane, Data File is set to ex_DataFile.xml.

Click Run This Check. The Model Advisor check warns that the configuration parameters are not set to the values specified in ex_DataFile.xml. For configuration parameters with positive constraint tagging (PositiveModelParameterConstraint), the recommended values are obtained from the value tagging. For configuration parameters with negative constraint tagging (NegativeModelParameterConstraint), the values not recommended are obtained from the value tagging.

  • Algebraic loop(AlgebraicLoopMsg) - the ex_DataFile.xml tagging does not specify a fix action for AlgebraicLoopMsg. The subcheck passes only when the setting is not set to none.

  • Minimize algebraic loop(ArtificialAlgebraicLoopMsg) - the ex_DataFile.xml tagging specifies a subcheck with a fix action for ArtificialAlgebraicLoopMsg that passes only when the setting is error. The fix action modifies the setting to error.

  • Block priority violation(BlockPriorityViolationMsg) - the ex_DataFile.xml tagging specifies a subcheck with a fix action for BlockPriorityViolationMsg that does not pass when the setting is warning. The fix action modifies the setting to error.

In the Action section of the Model Advisor dialog box, click Modify Settings. Model Advisor updates the configuration parameters for Block priority violation and Minimize algebraic loop.

Run By Task > Example: My Group > Example: Check model configuration parameters. The check warns because Algebraic loop is set to none.

In the right pane of the Model Advisor window, use the Algebraic loop (AlgebraicLoopMsg) link to open the Simulation > Model Configuration Parameters > Diagnostics. Set Algebraic loop to warning or error.

Run By Task > Example: My Group > Example: Check model configuration parameters. The check passes.

Data File for Configuration Parameter Check

You use an XML data file to create a configuration parameter check. To create the data file, you can use Advisor.authoring.generateConfigurationParameterDataFile or manually create the file yourself. The data file contains tagging that specifies check behavior. Each model configuration parameter specified in the data file is a subcheck. The structure for the data file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<customcheck xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://www.w3schools.com 
MySchema.xsd">
    <messages>    
        <Description>Description of check</Description>    
        <PassMessage>Pass message</PassMessage>
        <FailMessage>Fail message</FailMessage>
        <RecommendedActions>Recommended action</RecommendedActions>        
    </messages>
    <checkdata>
    <!--Command line name of configuration parameter-->
        <PositiveModelParameterConstraint>
            <parameter>Command-line name of configuration parameter</parameter>
            <value>Value that you want configuration parameter to have</value>
            <fixvalue>Specify value for a fix action</fixvalue>
            <dependson>ID of configuration parameter subcheck that must pass 
                    before this subcheck runs</value>    
        </PositiveModelParameterConstraint>
    <!-- Command line name of configuration parameter-->
        <NegativeModelParameterConstraint>
            <parameter>Command line name of configuration parameter</parameter>
            <value>Value that you do not want configuration parameter to have</value>
            <fixvalue>Specify value for a fix action</fixvalue>
            <dependson>ID of configuration parameter subcheck that must pass 
                    before this subcheck runs</value>
        </NegativeModelParameterConstraint>
     </checkdata>
</customcheck>

The <messages> tag contains:

  • Description - (Optional) Description of the check. Displayed in Model Advisor window.

  • PassMessage - (Optional) Pass message displayed in Model Advisor window.

  • FailMessage - (Optional) Fail message displayed in Model Advisor window.

  • RecommendedActions - (Optional) Recommended actions displayed in Model Advisor window when check does not pass.

Note

The <messages> tag is optional. Advisor.authoring.generateConfigurationParameterDataFile does not generate <messages> tagging.

In the <checkdata> tag, the data file specifies two types of constraints:

  • PositiveModelParameterConstraint - Specifies the configuration parameter setting that you want.

  • NegativeModelParameterConstraint - Specifies the configuration parameter setting that you do not want.

Within the tag for each of the two types of constraints, for each configuration parameter that you want to check, the data file has the following tags:

  • parameter - Specifies the configuration parameter that you want to check. The tagging uses the command line name for the configuration parameter. For example:

    <PositiveModelParameterConstraint>
        <parameter>BlockPriorityViolationMsg</parameter>
    </PositiveModelParameterConstraint>
    <NegativeModelParameterConstraint>
        <parameter>AlgebraicLoopMsg</parameter>
    </NegativeModelParameterConstraint>

  • value - Specifies the setting(s) for the configuration parameter. You can specify more than one value tag.

    When using PositiveModelParameterConstraint, value specifies the setting(s) that you want for the configuration parameter. For NegativeModelParameterConstraint, value specifies the setting(s) you that do not want for the configuration parameter.

    You can specify the value using a format in this table.

    TypeFormatExample
    Scalar value
    <value>xyz</value>

    In this example, NegativeModelParameterConstraint constraints warn when the configuration parameter settings for configuration parameter is not error or none .

    <NegattiveModelParameterConstraint>
        <value>error</value>
        <value>none</value>
    </NegativeModelParameterConstraint>

    Structure or object
    <value>
        <param1>xyz</param1>
        <param2>yza</param2>
    </value>

    In this example, PositiveModelParameterConstraint constraints warn when the configuration parameter settings are not a valid structure:

    <PositiveModelParameterConstraint>
        <value>
            <double>a</double>
            <single>b</single>
        </value>
    </PositiveModelParameterConstraint>

    Array
    <value>
        <element>value</element>
        <element>value</element>
    </value>

    In this example, NegativeModelParameterConstraint constraints warn when the configuration parameter settings are an invalid array:

    <NegativeModelParameterConstraint>
        <value>
            <element>A</element>
            <element>B</element>   
        </value>
    </NegativeModelParameterConstraint>

    Structure Array
    <value>
        <element>
            <param1>xyz</param1>
            <param2>yza</param2>
        </element>
        <element>
            <param1>xyz</param1>
            <param2>yza</param2>
        </element>
    </value>
    

    In this example, NegativeModelParameterConstraint constraints warn when the configuration parameter settings are an invalid structure array:

    <NegativeModelParameterConstraint>    
        <value>
            <element>
                <double>a</double>
                <single>b</single>
           </element>
           <element>
                <double>a</double>
                <single>b</single>
           </element>
        </value>
    </NegativeModelParameterConstraint>

  • fixvalue - (Optional) Specifies the setting to use when applying the Model Advisor fix action.

    You can specify the fixvalue using a format in this table.

    TypeFormatExample
    Scalar value
    <fixvalue>xyz</fixvalue>

    In this example, the fix action tag specifies the new configuration parameter setting as warning.

    <PositiveModelParameterConstraint>
        <value>error</value>
        <fixaction>warning</fixaction>
    </PositiveModelParameterConstraint>
    Structure or object
    <fixvalue>   
        <param1>xyz</param1>
        <param2>yza</param2>
    </fixvalue>

    In this example, the fix action tag specifies the new configuration parameter setting for a structure.

    <PositiveModelParameterConstraint>
        <value>
            <double>a</double>
            <single>b</single>
        </value>
        <fixvalue>
            <double>c</double>
            <single>d</single>    
        </fixvalue>
    </PositiveModelParameterConstraint>
    Array
    <fixvalue>
        <element>value</element>
        <element>value</element>
    </fixvalue>

    In this example, the fix action tag specifies the new configuration parameter setting for an array.

    <NegativeModelParameterConstraint>
        <value>
            <element>A</element>
            <element>B</element>   
        </value>
        <fixvalue>
            <element>C</element>
            <element>D</element>
        </fixvalue>
    </NegativeModelParameterConstraint>
    Structure Array
    <fixvalue>
        <element>
            <param1>xyz</param1>
            <param2>yza</param2>
        </element>
        <element>
            <param1>xyz</param1>
            <param2>yza</param2>
        </element>
    </fixvalue>
    

    In this example, the fix action tag specifies the new configuration parameter settings for a structure array.

    <NegativeModelParameterConstraint>    
        <value>
            <element>
                <double>a</double>
                <single>b</single>
           </element>
            <element>
                <double>a</double>
                <single>b</single>
            </element>
        </value>
        <fixvalue>
            <element>
                <double>c</double>
                <single>d</single>
            </element>
            <element>
                <double>c</double>
                <single>d</single>
            </element>
        </fixvalue>
    </NegativeModelParameterConstraint>

  • dependson - (Optional) Specifies a prerequisite subcheck.

    In this example, dependson specifies that configuration parameter subcheck ID_B must pass before configuration parameter subcheck ID_A runs.

    <PositiveModelParameterConstraint id="ID_A">
        <dependson>ID_B</value>
    </PostitiveModelParameterConstraint>

Data file tagging specifying a configuration parameter

The following tagging specifies a subcheck for configuration parameter SolverType. If the configuration parameter is set to Fixed-Step, the subcheck passes.

<PositiveModelParameterConstraint id="ID_A">    
    <parameter>SolverType</parameter>
    <value>Fixed-step</value>
</PostitiveModelParameterConstraint>

Data file tagging specifying configuration parameter with fix action

The following tagging specifies a subcheck for configuration parameter AlgebraicLoopMsg. If the configuration parameter is set to none or warning, the subcheck passes. If the subcheck does not pass, the check fix action modifies the configuration parameter to error.

<PositiveModelParameterConstraint id="ID_A">    
    <parameter>AlgebraicLoopMsg</parameter>
    <value>none</value>    
    <value>warning</value>
    <fixvalue>error</value>
</PostitiveModelParameterConstraint>

Data file tagging specifying an array type configuration parameter

<PositiveModelParameterConstraint id="A">
    <parameter>ReservedNameArray</parameter>
    <value>
        <element>A</element>
        <element>B</element>
    </value>
    <value>
        <element>A</element>
        <element>C</element>
    </value>
</PositiveModelParameterConstraint>

Data file tagging specifying a structure type configuration parameter with fix action

<PositiveModelParameterConstraint id="A">    
    <parameter>ReplacementTypes</parameter>
    <value>
        <double>a</double>
        <single>b</single>
    </value>
    <value>
        <double>c</double>
        <single>b</single>
    </value>
    <fixvalue>
        <double>a</double>
        <single>b</single>
    </fixvalue>
</PositiveModelParameterConstraint>

Data file tagging specifying configuration parameter with fix action and prerequisite check

The following tagging specifies a subcheck for configuration parameter SolverType. The subcheck for SolverType runs only after the ID_B subcheck passes. If theID_B subcheck does not pass, the subcheck for SolverType does not run. The Model Advisor reports that the prerequisite constraint is not met.

If the SolverType subcheck runs and SolverType is set to Fixed-Step, the SolverType subcheck passes. If the subcheck runs and does not pass, the check fix action modifies the configuration parameter to Fixed-Step.

<PositiveModelParameterConstraint id="ID_A">
    <parameter>SolverType</parameter>
    <value>Fixed-step</value>    
    <fixvalue>Fixed-step</value>
    <dependson>ID_B</value>
</PostitiveModelParameterConstraint>

Data file tagging specifying unwanted configuration parameter

The following tagging specifies a subcheck for configuration parameter SolverType. The subcheck does not pass if the configuration parameter is set to Fixed-Step.

<NegativeModelParameterConstraint id="ID_A">    
    <parameter>SolverType</parameter>
    <value>Fixed-step</value>
</NegativeModelParameterConstraint>

Data file tagging specifying unwanted configuration parameter with fix action

The following tagging specifies a subcheck for configuration parameter SolverType. If the configuration parameter is set to Fixed-Step, the subcheck does not pass . If the subcheck does not pass, the check fix action modifies the configuration parameter to Variable-Step.

<NegativeModelParameterConstraint id="ID_A">    
    <parameter>SolverType</parameter>    
    <value>Fixed-step</value>    
    <fixvalue>Variable-step</value>
</NegativeModelParameterConstraint>

Data file tagging specifying unwanted configuration parameter with fix action and prerequisite check

The following tagging specifies a check for configuration parameter SolverType. The subcheck for SolverType runs only after the ID_B subcheck passes. If theID_B subcheck does not pass, the subcheck for SolverType does not run. The Model Advisor reports that the prerequisite constraint is not met.

If the SolverType subcheck runs and SolverType is set to Fixed-Step, the subcheck does not pass. The check fix action modifies the configuration parameter to Variable-Step.

<NegativeModelParameterConstraint id="ID_A">    
    <parameter>SolverType</parameter>
    <value>Fixed-step</value>
    <fixvalue>Variable-step</value>
    <dependson>ID_B</value>
</NegativeModelParameterConstraint>

See Also

| | |

Related Topics