Real-Time Workshop    

Tutorial 3: Code Validation

In this tutorial, the code generated from the f14rtw model is validated against the model. The code is validated by capturing and comparing data from runs of the Simulink model and the generated program.

Logging Signals via Scope Blocks

This example uses Scope blocks (rather than Outport blocks) to log both input and output data. To configure the Scope blocks to log data:

  1. Before proceeding with this tutorial, clear the workspace and reload the model so that the proper workspace variables are declared and initialized:
  2. Open the Stick Input Scope block and click on the Parameters button on the toolbar of the Scope window. The Scope Properties dialog box opens.
  3. Select the Data History tab of the Scope Properties dialog box.

  4. Select the Save data to workspace option and enter the name of the variable (Stick_input) that is to receive the scope data.
  1. In the example above, the Stick Input signal to the scope block will be logged to the array Stick_input during simulation. The generated code will log the same signal data to the MAT-file variable rt_Stick_input during a run of the executable program.

  1. Click the Apply button.
  2. Configure the Pilot G Force and Angle of Attack Scope blocks similarly, using the variable names Pilot_G_force and Angle_of_attack.
  3. Save the model.

Logging Simulation Data

The next step is to run the simulation and log the signal data from the Scope blocks:

  1. Open the Stick Input, Pilot G Force, and Angle of Attack Scope blocks.
  2. Run the model. The Scope blocks display.

  3. Use the whos command to observe that the array variables Stick_input, Pilot_G_force, and Angle_of_attack have been saved to the workspace.
  4. Plot one or more of the logged variables against simulation time. For example:

Logging Data from the Generated Program

Since you have modified the model, you must rebuild and run the f14rtw executable in order to obtain a valid data file:

  1. Select Build Model from the Real-Time Workshop menu of the Tools menu in the Simulink window.
  2. When the build completes, run the stand-alone program from MATLAB:
  3. Load the data file f14rtw.mat and observe the workspace variables:
  1. The data loaded from the MAT-file will include rt_Pilot_G_force, rt_Angle_of_attack, rt_Stick_input, and rt_tout.

  1. You can now use MATLAB to plot the three workspace variables as a function of time.

Comparing Results of the Simulation
and the Generated Program

Your Simulink simulations and the generated code should produce nearly identical output.

You have now obtained data from a Simulink run of the model, and from a run of the program generated from the model. It is a simple matter to compare the f14rtw model output to the results achieved by Real-Time Workshop.

Comparing Angle_of_attack (simulation output) to rt_Angle_of_attack (generated program output) produces

Comparing Pilot_G_force (simulation output) to rt_Pilot_G_force (generated program output) produces

Overall agreement is within 10-13. This slight error can be caused by many factors, including

For example, a function such as sin(2.0) may return a slightly different value, depending on which C library you are using.

For the same reasons, your comparison results may not be identical to those above.


  Tutorial 2: Data Logging Tutorial 4: A First Look at Generated Code