Contenu principal

Configure Model Parameters with Tuning Service Interface Definitions

R2026b

A generated-code variable corresponding to a model parameter, can be tuned at during program execution if the parameter is configured as tunable before code generation.

Because the parameter is configured as tunable, the ASAP2 file includes a section that describes its tuning properties. To learn more about generated ASAP2 files, see:

There are five general types of model parameters that can be tuned with ASAP2 files:

  • Model Parameters Arguments

  • Model Parameters

  • Model Variant Control Arguments

  • Model Variant Controls

  • Model Variant Variables

For information about model parameters, see Simulink.Parameter, Simulink.VariantVariable, and Simulink.VariantControl.

Map Model Parameters to Parameter Tuning Service Interface Definitions

This example shows how to map model parameters to tuning service interface definitions for code generation, using the Initial condition of a Unit Delay block and the Initial output of the Merge block.

To allow tuning these model parameters during program execution:

  1. Before generating code, configure the parameter as tunable and specify its tuning properties.

  2. Generate code for the model.

  3. Generate an ASAP2 file.

Open Explore Model

Open the component model ControllerSWC.

soaControlModel = "ControllerSWC";
open_system(soaControlModel);

Model ControllerSWC.

In the example you,

  1. Create Simulink® Parameter objects using Model Explorer.

  2. Assign the parameter objects to specific block parameters.

  3. Configure these block parameters with tuning service interface definitions.

  4. Generate model code that exports the variables corresponding to those parameters.

  5. Generate ASAP2 files that contain the description of these parameters.

Use Parameters in Model

The Unit Delay block has a configurable Initial condition parameter and the Merge block has a configurable Initial output parameter. Add Simulink parameters to the model workspace and assign them as the values for these block parameters.

Add Parameters to Model:

  1. Open the model workspace: from the Modeling tab of the Simulink editor, in the Design section, click the arrow to open the gallery. Then, in the Design section, click the Model Explorer button Model Explorer button..

  2. In the left pane, navigate to the Model Workspace tree branch. Then, click Add in the menu bar, and then select Simulink Parameter.

Add two Simulink parameters with the names UD_Param and MergeParam. Set the value of each of them to 0. Designate MergeParam as an argument by selecting the Argument checkbox.

Model Explorer with the Model Workspace item selected on the left pane. The Add menu bar item is highlighted and the mouse cursor is selecting the Simulink Parameter from the list that is open under the Add item. In the middle pane there are two Simulink Parameters, UD_Param and MergeParam, with value 0. The Argument checkbox of MergeParam is selected.

Assign Model Parameters to Block Parameters:

Double click the Unit Delay and the Merge blocks to open their model parameter dialog boxes. In the Initial condition parameter of the Unit Delay block type UD_Param and in the Initial output parameter of the Merge block type MergeParam. Click OK in both.

Block parameter dialog boxes of the Unit Delay and Merge bock. The values of Initial condition in the Unit Delay block and the Initial output of the Merge block are UD_Param and MergeParam, respectively.

Open Service Mappings Editor

Open the Service Mappings editor by pressing Ctrl+Shift+C. Then, select the Parameters tab.

Service Mappings editor with the Parameters tab selected. The parent entries Model Parameter Arguments and Model Parameters have each one child entry. The parent entries Model Variant Control Arguments, Model Variant Controls, and Model Variant Variables have no child entries.

There are five parent entries in the table, each corresponding to one type of model parameters. The Model Parameters and Model Parameter Arguments entries have each one child entry, MergeParam and UD_Param, respectively.

Configure Parameter Tuning Service

The Parameter Tuning Service property determines whether the generated code that represents tunable elements can be tuned during program execution or not. For both MergeParam and UD_Param, set Parameter Tuning Service to Tunable.

Calibration Properties

When the Parameter Tuning Service of a model parameter is set to Tunable, the generated ASAP2 file contains a section that corresponds to the parameter and contains the calibration properties of the parameter. This allows calibration tools to measure and tune the value of the corresponding variable during program execution. To configure calibration properties of a model parameter:

  1. Select the Parameters tab of the Service Mappings editor.

  2. In the table, locate the entry of the model parameter.

  3. Click the pencil icon at the end of the entry to open a dialog box in which you configure the calibration properties of the model parameter.

The Identifier property of the model parameter is not one of the calibration properties, but you configure it also in the dialog box. Use this property to specify the name of the variable that corresponds to the model parameter, in the code generated from the model. If you leave the value of this property empty, the name of the corresponding variable is the name of the model parameter itself.

When the Calibration Access property of a model parameter is set to NoCalibration, the calibration tool is blocked from modifying the variable value. However, the variable is still exported in the code, and the ASAP2 file contains a section that corresponds to the parameter, and the calibration tool can still read the variable value.

Specify these calibration properties for the parameters UD_Param and MergeParam:

 

UD_Param

MergeParam

Corresponding Property

in ASAP2 File

Identifier

UD_ParamID

mergeParamID

Name

Calibration Access

(Only shown when

value is NoCalibration)

NoCalibration

Calibration

CALIBRATION_ACCESS

Display Identifier

UD_ParamDispID

MergeParamDispID

DISPLAY_IDENTIFIER

Format

Leave empty

%2.1

FORMAT

Compu Method

Leave empty

myCompMethod

Conversion method

Mouse cursor is on the pencil icon for the MergeParam parameter in the Service Mappings editor. The Additional Properties dialog box is open with these property values: Identifier:outputSignalVal, Calibration Access:Calibration,Display Identifier:dispID_MergeParam,Format:%2,1,Compu Method:myCompMethod.

Generate Model Code and Calibration Files

Generate code from the model.

evalc("slbuild(soaControlModel,GenerateCodeOnly=true)");

To generate the calibration file, on the Software Component tab of the Simulink Toolstrip, select Share > Generate Calibration Files.

Model ControllerSWC with the Software Component tab selected in the Simulink Toolstrip. The gallery of the Share button is open with the Generate Calibration Files item in the Calibration section labeled.

In the Generate Calibration Files dialog box, make sure that Generate ASAP2 switch is set to on and, since you are not using address replacement, make sure the Address replacement is cleared. Then, click Generate.

Generate Calibration Files dialog box.

In the generated file ControllerSWC.a2l, locate the sections that correspond to the model parameters UD_Param and mergeParam. The beginning marker of each of these sections is /begin CHARACTERISTIC and the end marker is /end CHARACTERISTIC. Each section consists of the calibration properties of the model parameter it corresponds to.

  /begin CHARACTERISTIC 
    /* Name                   */      ControllerSWC_Params.mergeParamID
    /* Long Identifier        */      ""
    /* Type                   */      VALUE
    /* ECU Address            */      0x0000 /* @ECU_Address@ControllerSWC_Params.mergeParamID@ */
    /* Record Layout          */      Record_BOOLEAN
    /* Maximum Difference     */      0
    /* Conversion Method      */      myCompMethod
    /* Lower Limit            */      0
    /* Upper Limit            */      1
    DISPLAY_IDENTIFIER MergeParamDispID
    FORMAT "%2.1"
  /end CHARACTERISTIC 

  /begin CHARACTERISTIC 
    /* Name                   */      UD_ParamID
    /* Long Identifier        */      ""
    /* Type                   */      VALUE
    /* ECU Address            */      0x0000 /* @ECU_Address@UD_ParamID@ */
    /* Record Layout          */      Record_BOOLEAN
    /* Maximum Difference     */      0
    /* Conversion Method      */      CM_boolean
    /* Lower Limit            */      0
    /* Upper Limit            */      1
    CALIBRATION_ACCESS NO_CALIBRATION
    DISPLAY_IDENTIFIER UD_ParamDispID
  /end CHARACTERISTIC

Note how each of these sections matches the calibration properties of the model parameter it corresponds to.

See Also

|

Topics