Parameter Tuning and Signal Logging

Methods For Parameter Tuning and Signal Logging

The Target Support Package IC1 product supports parameter tuning and signal logging either using Simulink external mode or with a third party calibration tool. In both cases the model must include a special block, the CAN Calibration Protocol block.

Using External Mode

The Simulink external mode feature enables you to log signals and tune parameters without requiring a calibration tool. This section describes the steps for converting a model to use external mode.

External mode is supported using the CAN Calibration Protocol block and ASAP2 interface. The CAN Calibration Protocol block is used to communicate with the target, downloading parameter updates and uploading signal information. The ASAP2 interface is used to get information about where in the target memory a parameter or signal lives.

To prepare your model for external mode, follow these steps:

  1. Add a CCP driver block.

  2. Add a Switch External Mode Configuration Block (for ease of use; you can also make changes manually).

  3. Identify signals you want to tune, and associate them with Simulink.Parameter objects with ExportedGlobal storage class. It is important to set the data type and value of the Simulink.Parameter object. See Using Supported Objects and Data Types.

  4. Identify signals you want to log, and associate them with canlib.Signal objects. It is important to set the data type of the canlib.Signal. See Using Supported Objects and Data Types.

    For information about visualizing logged signal data, see Viewing and Storing Signal Data.

  5. Load the the Simulink.Parameter and canlib.Signal data objects into the base workspace.

  6. Configure the model for building by double-clicking the Switch External Mode Configuration block. In the dialog box, select Building an executable, and click OK.

  7. Build the model, and download the executable to the target

  8. After downloading the executable to the target, you can switch the model to external mode by double-clicking the Switch External Mode Configuration Block. In the dialog box that appears, select External Mode, and click OK.

  9. You can now connect to the target using external mode by clicking the Connect button.

  10. If you have set up tunable parameters, you can now tune them. See Tuning Parameters.

If you do not want to use the Switch External Mode Configuration block, you can configure for building and then external mode manually. For instructions, see Manual Configuration For External Mode.

See the following topics for more information:

Configuring the Host Vector CAN Application Channel

External mode expects that the host-side CAN connection is using the 'MATLAB 1' application channel. To configure the application channel used by the Vector CAN drivers, enter the following at the MATLAB command line:

TargetsComms_VectorApplicationChannel.configureApplicationChannels

The Vector CAN Configuration tool appears. Use this tool to configure your host-side CAN channel settings.

If you try to connect using an application channel other than 'MATLAB 1', then you see the following warning in the command window:

Warning:
It was not possible to connect to the target using CCP. 
An error occurred when issuing the CONNECT command. 

Using Supported Objects and Data Types

Supported objects:

Supported data types:

You need to define data objects for the signals and parameters of interest for ASAP 2 file generation. For ease of use, create an m-file to define the data objects, so that you only have to set up the objects once.

To set up tuneable parameters and signal logging:

  1. Associate the parameters to be tuned with Simulink.Parameter objects with ExportedGlobal storage class. It is important to set the data type and value of the Simulink.Parameter object. See the following m-code for an example of how to create such a Simulink.Parameter object for tuning:

    stepSize = Simulink.Parameter;
    stepSize.DataType = 'uint8';
    stepSize.RTWInfo.StorageClass = 'ExportedGlobal';
    stepSize.Value = 1;
  2. Associate the signals to be logged with canlib.Signal objects. It is important to set the data type of the canlib.Signal. The following m-code example shows how to declare such a canlib.Signal object for logging:

    counter = canlib.Signal;
    counter.DataType = 'uint8'; 
  3. Associate the data objects you have defined in the m-file with parameters or signals in the model. For the previous m-code examples, you could set the Constant value in a Source block to stepSize, and set a Signal name to counter in the Signal Properties dialog box. Remember that stepSize and counter are data objects defined in the m-code.

Tuning Parameters

To tune a parameter, follow these steps:

  1. Set dataobject.value in the workspace while the model is running in external mode. For example, to tune the parameter stepSize (that is, to change its value) from 1 to 2, enter the following at the command line:

    stepSize.value = 2
     

    You see output similar to the following:

    stepSize =
     
    Simulink.Parameter (handle)
            RTWInfo: [1x1 Simulink.ParamRTWInfo]
        Description: ''
           DataType: 'uint8'
                Min: -Inf
                Max: Inf
           DocUnits: ''
              Value: 2
         Complexity: 'real'
         Dimensions: [1 1]
  2. Return to your model, and update the model (press Ctrl+D) to apply the changed parameter.

Viewing and Storing Signal Data

To view the logged signals attach a supported scope type to the signal (see Limitations for supported scope types).

Select which signals you want to log by using the External Signal & Triggering dialog box. Access the External Mode Control Panel from the Tools menu, and click the Signal & Triggering button. By default, all displays appear as selected to be logged, as shown in the following example. Edit these settings if you do not want to log all displays. Individual displays can be selected manually.

Storing signal data for further analysis. It is possible to store the logged data for further analysis in MATLAB.

  1. To use the Data Archiving feature of external mode, click Data Archiving in the External Mode Control Panel. The External Data Archiving dialog box appears.

    1. Select the check box Enable archiving

    2. Edit the Directory and Filename and any other desired settings.

    3. Close the dialog box.

  2. Open the Scope parameters, and select the check box Save data to workspace.

  3. You may want to edit the Variable name in the edit box. The data that is displayed on the scope at the end of the external mode session is available in the workspace with this variable name.

    The data that was previously displayed in the scope is stored in .mat files as previously setup using Data Archiving.

    For example, at the end of an external mode session, the following variable and files could be available in the workspace and current directory:

Manual Configuration For External Mode

As an alternative to using the Switch External Mode Configuration block, you can configure models manually for build and execution with external mode.

To configure a model to be built for external mode:

  1. Select Inline parameters (under Optimization in the Configuration Parameters dialog box). The Inline parameters option is required for ASAP2 generation.

  2. Select Normal simulation mode (in either the Simulation menu, or the drop-down list in the toolbar).

  3. Select ASAP2 as the Interface (under Real-Time Workshop, Interface, in the Data Exchange pane, in the Configuration Parameters dialog box).

After you build the model, you can configure it for external mode execution:

  1. Make sure Inline parameters are selected (under Optimization in the Configuration Parameters dialog box). The Inline parameters option is required for external mode.

  2. Select External simulation mode (in either the Simulation menu, or the drop-down list in the toolbar).

  3. Select External mode as the Interface (under Real-Time Workshop, Interface, in the Data Exchange pane, in the Configuration Parameters dialog box).

Limitations

Logging of multiple signals feeding the same scope block is not supported. Instead, log each signal with its own scope block. These multiple signals can be on the same Simulink line, or can be multiple lines feeding the same scope (i.e. the scope can have multiple axes).

Only the following kinds of scopes are supported with External Mode Logging:

GRT is supported but only for parameter tuning.

If a signal comes directly from a Rate Transition block, external mode may fail to detect the correct sample time. To work around this, place a non-virtual block (e.g., Contiguous Copy) in between the Rate Transition block and the signal to log.

It is not possible to log signals with very fast sample times (e.g., 0.0001) without losing data.

Subsystem builds are not supported for external mode, only top-level builds are supported.

Logging and tuning of nonscalars is not supported. It is possible to log nonscalar signals by breaking the signal down into its scalar components. For an example of how to do this signal deconstruction, see the CCP demo models, which use a Demux and Signal Conversion block with contiguous copy.

Logging and tuning of complex numbers is not supported. It is possible to work with complex numbers by breaking the complex number down into its real and imaginary components. This breakdown can be performed using the following blocks in the Simulink Math Operations library: Complex to Real-Imag, Real-Imag to Complex, Magnitude-Angle to Complex, Complex to Magnitude-Angle.

Using a Third Party Calibration Tool

The Target Support Package IC1 product allows an ASAP2 data definition file to be generated during the code generation process. This file can be used by a third party tool to access data from the real-time application while it is executing.

ASAP2 is a data definition standard by the Association for Standardization of Automation and Measuring Systems (ASAM). ASAP2 is a standard description for data measurement, calibration, and diagnostic systems. The Target Support Package IC1 product lets you export an ASAP2 file containing information about your model during the code generation process. See also Compatibility with Calibration Packages.

Before you begin generating ASAP2 files with the Target Support Package IC1 product, you should read the Generating ASAP2 Files section of the Real-Time Workshop documentation. That section describes how to define the signal and parameter information required by the ASAP2 file generation process.

Select the ASAP2 option before the build process as follows:

  1. Select Simulation > Configuration Parameters.

    The Configuration Parameters dialog box appears.

  2. Select Interface (under Real-Time Workshop) in the tree.

  3. Select the ASAP2 option from the Interface drop-down menu, in the Data exchange frame, as shown following.

  4. Click Apply.

The build process creates an ASAM-compliant ASAP2 data definition file for the generated C code.

The Target Support Package IC1 product performs this postprocessing for you. To do this, it first extracts the memory address information from the map file generated during the link process. Secondly, it replaces the placeholders in the ASAP2 file with the actual memory addresses. This postprocessing is performed automatically and requires no additional input from you.

For an example of a model that is configured to generate an ASAP2 file, see c166_ccp.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS