By default, code generation optimizations eliminate storage for model parameters and most signals that do not participate in the entry-point function interface. To make parameters tunable and related signals accessible, identify them by configuring them explicitly.
In the BasicRollMode
subsystem of model
rtwdemo_roll
, configure a PID control parameter to appear in the code as a
global variable whose value you can tune.
Open the BasicRollMode
subsystem.
In the Model Data Editor, select the Parameters tab.
In the filter field, type IntGain
. The Model Data Editor shows a
row that corresponds to the Gain parameter and a row that corresponds
to a workspace variable.
In the Source column, click IntGain
. That Gain
block appears highlighted in the model diagram.
In the Name column, click the model workspace variable
intGain
.
Convert the model workspace variable to a parameter object. In the Storage
Class column, select Convert to parameter object
.
Change the Storage Class setting to Model
default
, which indicates that the parameter object prevents code
generation optimizations from eliminating storage for the variable. With this setting, the
object uses the storage class specified in the Code Mappings editor as the data default
for category Model parameters.
Save the model and regenerate the code.
Minimize the code generation report window for exploration later in this tutorial.
In the Code view:
Search for intGain
.
In rtwdemo_roll.c
, place your cursor over the ellipsis menu
over the P
in the highlighted code P.intGain
.
In the model editor, notice that the Code view highlights the block corresponding to
the generated code.
To see the parameter object definition for intGain
in
rtwdemo_roll_data.c
, click the definition code in the dialog
box.
The code that you generate from the model stores the parameter object in memory. Because
you left the default storage class settings in the Code Mapping Editor for category
Model parameters set to Default
, the code
generator determines the storage format, for example, as fields of structures.
Next, use a test harness model and software-in-the-loop (SIL) simulation to compare results of model simulation and generated code.