Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

Creating Custom Objectives

The Code Generation Advisor reviews your model based on objectives that you specify. If the predefined efficiency, traceability, safety precaution, and debugging objectives do not meet your requirements, you can create custom objectives.

You can create custom objectives by:

Specifying Parameters in Custom Objectives

When you create a custom objective, you specify the values of configuration parameters that the Code Generation Advisor reviews using the following methods:

Specifying Checks in Custom Objectives

All objectives include the Check model configuration settings against code generation objectives check by default. When you create a custom objective, you specify the list of additional checks that are associated with the custom objective using the following methods:

Determining Checks and Parameters in Existing Objectives

When you base a new objective on an existing objective, you can determine what checks and parameters the existing objective contains. Select the existing objective and check the model. The Code Generation Advisor lists the checks and parameters associated with the existing objective.

The Code Generation Advisor contains the list of checks in each objective. For example, the Efficiency objective includes ten checks, which you can see in the Code Generation Advisor if you:

  1. Open the rtwdemo_rtwecintro model.

  2. Specify an ERT-based target.

  3. Specify the Efficiency objective.

  4. Check the model.

The Code Generation Advisor displays in the right pane the list of checks in the Efficiency objective.

The first check, Check model configuration settings against code generation objectives, lists all parameters and values specified by the objective. For example, the Code Generation Advisor displays the list of parameters and the recommended values in the Efficiency objective, if you:

  1. Run Check model configuration settings against code generation objectives.

  2. Click Modify Parameters.

  3. Rerun the check.

The Code Generation Advisor displays in the check results the list of parameters and recommended values in the Efficiency objective.

How to Create Custom Objectives

To create a custom objective:

  1. Create an sl_customization.m file.

      Note  

      • Specify all custom objectives in a single sl_customization.m file only, or the software generates an error. This holds true even if you have more than one sl_customization.m file on your MATLAB path.

      • Except for the matlabroot/work folder, do not place an sl_customization.m file in your root MATLAB folder, or any of its subfolders. Otherwise, the software ignores the customizations that the file specifies.

  2. Create an sl_customization function that takes a single argument. When the software invokes the function, the value of this argument is the Simulink customization manager. In the function:

    1. Create a handle to the code generation objective, using the ObjectiveCustomizer constructor.

    2. Register a callback function for the custom objectives, using the ObjectiveCustomizer.addCallbackObjFcn method.

    3. Add a call to execute the callback function, using the ObjectiveCustomizer.callbackFcn method.

    For example

    function sl_customization(cm)
    %SL_CUSTOMIZATION objective customization callback
    
    objCustomizer = cm.ObjectiveCustomizer;
    index = objCustomizer.addCallbackObjFcn(@addObjectives);
    objCustomizer.callbackFcn{index}();
    
    end
  3. Create a callback function which includes M-code to:

    The following example shows you how to create an objective, Reduce RAM Example. Reduce RAM Example includes five parameters and three checks that the Code Generation Advisor reviews:

    function addObjectives
    
    % Create the custom objective
    obj = rtw.codegenObjectives.Objective('ex_ram_1');
    setObjectiveName(obj, 'Reduce RAM Example');
    
    % Add parameters to the objective
    addParam(obj, 'InlineParams', 'on');
    addParam(obj, 'BooleanDataType', 'on');
    addParam(obj, 'OptimizeBlockIOStorage', 'on');
    addParam(obj, 'EnhancedBackFolding', 'on');
    addParam(obj, 'BooleansAsBitfields', 'on');
    
    % Add additional checks to the objective
    % The Code Generation Advisor automatically includes 'Check model
    % configuration settings against code generation objectives' in every
    % objective.
    addCheck(obj, 'Identify unconnected lines, input ports, and output ports');
    addCheck(obj, 'Check model and local libraries for updates');
    
    %Register the objective
    register(obj);
    
    end

    The following example shows you how to create an objective, My Traceability Example, based on the existing Traceability objective. The custom objective modifies, removes, and adds parameters that the Code Generation Advisor reviews. It also adds and removes checks from the Code Generation Advisor:

    function addObjectives
    
    % Create the custom objective from an existing objective
    obj = rtw.codegenObjectives.Objective('ex_my_trace_1', 'Traceability');
    setObjectiveName(obj, 'My Traceability Example');
    
    % Modify parameters in the objective
    modifyInheritedParam(obj, 'GenerateTraceReportSf', 'Off');
    removeInheritedParam(obj, 'ConditionallyExecuteInputs');
    addParam(obj, 'MatFileLogging', 'On');
    
    % Modify checks in the objective
    addCheck(obj, 'Identify questionable software environment specifications');
    removeInheritedCheck(obj, 'com.mathworks.MA.CheckDisableSignalLogging');
    
    %Register the objective
    register(obj);
    
    end
  4. If you previously opened the Code Generation Advisor, close the model from which you opened the Code Generation Advisor.

  5. Refresh the customization manager. At the MATLAB command line, enter the sl_refresh_customizations command.

  6. Open your model and review the new objectives.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS