Real-Time Workshop User's Guide | ![]() ![]() |
Parameter Objects
This section discusses how to use parameter objects in code generation.
Configuring Parameter Objects for Code Generation
In configuring parameter objects for code generation, you use the following code generation and parameter object properties:
Value
. This property is the numeric value of the object, used as an initial (or inlined) parameter value in generated code.RTWInfo.StorageClass
. This property controls the generated storage declaration and code for the parameter object.RTWInfo.TypeQualifier
. This property is a string included as a prefix in the generated storage declaration.Other parameter object properties (such as user-defined properties of classes derived from Simulink.Parameter) do not affect code generation.
Note
If Inline parameters is off (the default), the RTWInfo.StorageClass and RTWInfo.TypeQualifier parameter object properties are ignored in code generation.
|
Effect of Storage Classes on Code Generation for Parameter Objects
The Real-Time Workshop generates code and storage declarations based on the RTWInfo.StorageClass
property of the parameter object. The logic is as follows:
'Auto'
(the default), the parameter object is inlined (if possible), using the Value
property.'Auto'
, the parameter object is handled as a tunable parameter.See Table 3-7 for examples of code generated for each possible setting of RTWInfo.StorageClass
.
Example of Parameter Object Code Generation
In this section, we use the Gain block computations of the model shown in Figure 3-13 as an example of how the Real-Time Workshop generates code for a parameter object.
Figure 3-13: Model Using Parameter Object Kp As Block Parameter
In this model, Kp
sets the gain of the Gain1
block.
To configure a parameter object such as Kp
for code generation:
Simulink.Parameter
. In this example, the parameter object is an instance of the example class UserDefined.Parameter, which is provided with Simulink. For the definition of UserDefined.Parameter, see the directory matlabroot
/toolbox/simulink/simdemos/@UserDefined
.
Parameter
.
Kp = UserDefined.Parameter;
Make sure that the name of the parameter object matches the desired block parameter in your model. This ensures that Simulink can associate the parameter name with the correct object. For example, in the model of Figure 3-13, the Gain block parameter Kp resolves to the parameter object Kp.
Table 3-7 shows the variable declarations for Kp
and the code generated for the Gain block in the model shown in Figure 3-13, with Inline parameters on. An example is shown for each possible setting of RTWInfo.StorageClass
.
![]() | Overview | Signal Objects | ![]() |