Real-Time Workshop User's Guide    

Signal Objects

This section discusses how to use signal objects in code generation.

Configuring Signal Objects for Code Generation

In configuring signal objects for code generation, you use the following code generation options and signal object properties:

Effect of Storage Classes on Code Generation for Signal Objects

The way in which the Real-Time Workshop uses storage classes to determine how signals are stored is the same with and without signal objects. However, if a signal's label resolves to a signal object, the object's RTWInfo.StorageClass property is used in place of the port configuration of the signal.

The default storage class is Auto. If the storage type is Auto, the Real-Time Workshop follows the Signal storage reuse and Local block outputs code generation options to determine whether signal objects are stored in reusable and/or local variables. Make sure that these options are set correctly for your application.

To generate a a test point or externally-interfaceable signal storage declaration, use an explicit RTWInfo.StorageClass assignment. For example, setting the storage class to SimulinkGlobal, as in the following command, is equivalent to declaring a signal as a test point.

Example of Signal Object Code Generation

The discussion and code examples in this section refers to the model shown in Figure 3-14.

Figure 3-14: Example Model With Signal Object

To configure a signal object, you must first create it and associate it with a labelled signal in your model. To do this:

  1. Define a subclass of Simulink.Signal. In this example, the signal object is an instance of the example class UserDefined.Signal, which is provided with Simulink. For the definition of UserDefined.Signal, see the directory
    matlabroot/toolbox/simulink/simdemos/@UserDefined.
  2. Instantiate a signal object from your subclass. The following example instantiates SinSig, a signal object of class UserDefined.Signal.

    Make sure that the name of the signal object matches the label of the desired signal in your model. This ensures that Simulink can resolve the signal label to the correct object. For example, in the model shown in Figure 3-14, the signal label SinSig would resolve to the signal object SinSig.

  1. Set the object properties as required:

Table 3-8 shows, for each setting of RTWInfo.StorageClass, the variable declaration and the code generated for Sine Wave output (SinSig) of the model shown in Figure 3-14.

Table 3-8: Signal Properties Options and Generated Code
Storage Class
Declaration
Code

Auto

(with storage optimizations on)

    real_T rtb_temp0;
    (declared in 
    model_common.h)
    

    rtb_temp0 = (rtP.Sine_Wave_Amp) * 
    sin((rtP.Sine_Wave_Freq) * 
    ssGetT(rtS) + 
    (rtP.Sine_Wave_Phase));
    
    

Simulink Global

    typedef struct 
    BlockIO_tag {
      real_T SinSig; 
      real_T Gain1Sig;
    } BlockIO;
    .
    .
    BlockIO rtB;
    
    
    rtB.SinSig = (rtP.Sine_Wave_Amp) * 
    sin((rtP.Sine_Wave_Freq) * 
    ssGetT(rtS) + (rtP.Sine_Wave_Phase));
    
    

Exported Global

    extern real_T 
    SinSig;
    (declared in 
    model_export.h
    

    SinSig = (rtP.Sine_Wave_Amp) * 
    sin((rtP.Sine_Wave_Freq) * 
    ssGetT(rtS) + 
    (rtP.Sine_Wave_Phase));
    
    

Imported Extern

    extern real_T 
    SinSig;
    (declared in 
    model_common.h)
    

    SinSig = (rtP.Sine_Wave_Amp) * 
    sin((rtP.Sine_Wave_Freq) * 
    ssGetT(rtS) + 
    (rtP.Sine_Wave_Phase));
    
    

Imported Extern Pointer

    extern real_T 
    *SinSig;
    (declared in 
    model_common.h)
    

    *(SinSig) = (rtP.Sine_Wave_Amp) * 
    sin((rtP.Sine_Wave_Freq) * 
    ssGetT(rtS) + (rtP.Sine_Wave_Phase));
    
    


 Parameter Objects Object Property Information in the model.rtw File