Main Content

rtw.codegenObjectives.Objective

Custom code generation objective

Description

Use a code generation objective to specify a set of checks and parameters for the Code Generation Advisor to verify.

Creation

Description

rtw.codegenObjectives.Objective(newObjID) creates a new code generation objective that has the specified identifier.

example

rtw.codegenObjectives.Objective(newObjID, baseObjID) creates a code generation objective based on the specified existing code generation objective. The existing objective must be registered in the Code Generation Advisor.

Input Arguments

expand all

Identifier of new objective, specified as a character vector or string scalar.

Identifier of existing objective that the new objective is based on, specified as a character vector or string scalar.

Object Functions

setObjectiveNameSpecify objective name
addCheckAdd check to code generation objective
addParamAdd parameters to code generation objective
excludeCheckExclude check from code generation objective
modifyInheritedParamModify inherited parameter values in code generation objective
removeInheritedCheckRemove inherited check from objective
removeInheritedParamRemove inherited parameter from objective
registerRegister objective in Code Generation Advisor

Examples

collapse all

Create a custom objective named Reduced RAM Example that runs checks and verifies parameter values to confirm that the model is configured to reduce the RAM used by the generated code.

Create a file sl_customization.m to contain a callback function that creates the custom objective.

function sl_customization(cm)
%SL_CUSTOMIZATION objective customization callback

objCustomizer = cm.ObjectiveCustomizer;
index = objCustomizer.addCallbackObjFcn(@addObjectives);
objCustomizer.callbackFcn{index}();

end

Create and configure the objective in the addObjectives function. Set the name of the objective and add checks and parameters to verify. Then register the objective in the Code Generation Advisor.

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

Version History

Introduced in R2009a