Configure Model Parameter for Tuning and State Data for Measurement During Run Time
By default, code generation optimizations eliminate storage for model parameters and most
data store, signal, and state data that do not participate in the entry-point function
interface. In this case, in the model code mappings, the service interface for the element is
listed as Not tunable
or Not measurable
.
To make parameters tunable and data store, signal, and state data measurable during run time,
configure them to use a named parameter tuning or measurement service interface.
To enable parameter tuning and measurement of state data, use the code mappings for model
ComponentDeploymentFcn
to configure service interfaces for:
The state data for the Discrete-Time Integrator block in the
Integrator
subsystem.The
gain
parameter for the Gain block in theAccumulator
subsystem.The state data for the Unit Delay block in the
Accumulator
subsystem.
The code mappings for the state data also specify identifiers that the code generator uses for naming the variables representing that data. To see the identifier specifications, in the Code Mappings editor, on the Signals/States tab, select a state and click the pencil icon. In the dialog box that appears, note the setting of the Identifier property.
If not already open, in the Embedded Coder app, open example model
ComponentDeploymentFcn
.
Inspect the code interface settings.
Open the Code Mappings editor.
Click the Parameters tab. Model parameter
k
is mapped to the default parameter tuning service interfaceParameterTuningService
. Alternatively, you can selectNot tunable
.Click the Signals/States tab. The state data for the Discrete-Time Integrator and Unit Delay blocks are mapped to the default measurement service interface
MeasurementService
. Alternatively, for each state, you can selectNot measured
.
The storage classes associated with service interfaces
ParameterTuningService
and
MeasurementService
, TuningStruct
and
MeasurementStruct
, define structure type and instance variable names for
the data in the generated code as CD_tunable_T
,
CD_tunable.k
, CD_measured_T
,
CD_measured.dti
, and CD_measured.delay
.
In the Code view:
Search for
dti
.In
ComponentDeploymentFcn.c
, point toCD_measured
in the highlighted code.To see the variable definition for
CD_measured
, in the dialog box, click the definition code.
Consider searching for instances of the other data type and variable names:
CD_tunable_T
, CD_tunable.k
, and
CD_measured.delay
.
Next, simulate and verify the generated C code.