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:

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:

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:

  1. Define a subclass of 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.
  2. Instantiate a parameter object from your subclass. The following example instantiates Kp as a parameter object of class 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.

  1. Set the object properties.

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.

Table 3-7: Code Generation from Parameter Objects (Inline Parameters ON)
StorageClass Property
Generated Variable Declaration
and Code
Auto
    rtB.y = rtB.u * (5.0);
    
Simulink Global
    typedef struct Parameters_tag {
      real_T Kp;
    .
    .
    Parameters rtP = {
      5.0 
    };
    .
    .
    rtB.y = rtB.u * (rtP.Kp);
    
Exported Global
    real_T Kp = 5.0;
    .
    .
    rtB.y = rtB.u * (Kp);
    
    
Imported Extern
     extern real_T Kp;
    .
    .
    rtB.y = rtB.u * (Kp);
    
Imported Extern Pointer
    extern real_T *Kp;
    .
    .
    rtB.y = rtB.u * ((*Kp));
    


 Overview Signal Objects