Verify whether generated executable program results for the model match simulation results.
Configure the Dashboard Scope block to monitor the values
Force: f(t): 1 and
Double-click the Dashboard Scope block. In the Block
Parameters dialog box, confirm that:
The block is connected to signals
X. To connect a Dashboard
block to a signal, in the model canvas, select the signal. In the
Block Parameters dialog box, select the signal name.
Min is set to
Max is set to
Apply changes and close the dialog box.
Configure the Knob block so that you can use the knob to change the value of the damping gain. Double-click the Knob block. In the Block Parameters dialog box, confirm that:
The block is connected to parameter
Damping:Gain. To connect a Dashboard block to
a parameter, in the model canvas, select the block that uses the
parameter. In the Block Parameters dialog box, select the parameter
Minimum is set to
Maximum is set to
Tick Interval is set to
Apply changes and close the dialog box.
Open the Model Configuration Parameters dialog box. On the C Code tab, click Settings.
Configure the model such that Simulink® and the generated executable program log workspace data in the Simulation Data Inspector. Click Data Import/Export. Confirm that the model is configured with these settings:
|Parameter Selected||Name Set To|
|Record logged workspace data in Simulation Data Inspector|
Configure the model for building an executable program. Click Code Generation. Confirm that parameter Generate code only is cleared.
Configure and validate the toolchain for building the executable program.
Confirm that parameter Toolchain is set to
locate an installed toolchain. Then, search for and click
the Validate Toolchain button. The Validation Report
indicates whether the checks passed.
Configure parameters and signals so that the data is stored in memory and is accessible while the the executable program runs. To efficiently implement a model in C code, you do not allocate memory for every parameter, signal, and state in the model. If the model algorithm does not require data to calculate outputs, code generation optimizations eliminate storage for data. To allocate storage for the data so that you can access it during prototyping, you disable some optimizations.
Click Code Generation > Optimization. Confirm that:
Default parameter behavior is set to
Tunable. With this setting, block
parameters, such as the Gain parameter of a
Gain block, are tunable in the generated
Signal storage reuse is cleared. With this setting, the code generator allocates storage for signal lines. While running the executable program, you can monitor the values of these signals.
Configure the code generator to produce nonfinite data (for example,
Inf) and related
operations. Click Code Generation > Interface. Confirm that parameter Support: non-finite numbers is selected.
Configure a communication channel. For Simulink® to communicate with an executable program generated from a model, the model must include support for a communication channel. This example uses XCP on TCP/IP as the transport layer for a communication channel. Confirm these parameter settings:
External mode is selected.
Transport layer is set to
on TCP/IP. This selection specifies
ext_xcp for parameter Mex-file
Static memory allocation is selected. You cannot clear this parameter.
Static memory buffer size specifies the amount of XCP slave memory that is allocated for signal logging.
Disable MAT-file logging. Load the data into the Simulation Data Inspector from the MATLAB® base workspace. Confirm that parameter MAT-file logging is cleared.
Apply your configuration changes, close the Model Configuration Parameters dialog box, and save the model.
From the Simulink Editor, in the Simulation tab, click Run. The clock on the Run button indicates that simulation pacing is enabled. Simulation pacing slows down a simulation so that you can observe system behavior. Visualizing simulations at a slower rate makes it easier to understand the underlying system design and identify design issues while demonstrating near real-time behavior.
During the simulation, the Dashboard Scope block displays
the behavior of signals
Force: f(t):1 and
In the Simulink Editor, in the Simulation tab, click Data Inspector. The Simulation Data Inspector opens with data from your simulation run imported.
Expand the run (if not already expanded). Then, to plot the data, select
Leave these results in the Simulation Data Inspector. Later, you compare the simulation data to the output data produced by the executable program generated from the model.
Build and run the model executable program.
Click Monitor & Tune. Simulink:
Builds the executable program. During the build process
Building appears on the bottom-left corner of
the Simulink Editor window. When the code generation report appears
and the text reads
Ready, the process is
In Windows®, the code generator creates and places these files in your current working folder:
Executable program file
Debugging symbols file for parameters and
In Linux®, the code generator creates and places DWARF
format debugging information in the ELF executable program
places the file in your current working folder.
Deploys the executable program as a separate process on your development computer.
Connects the Simulink model to the executable program.
Runs the model executable program code.
Use the Simulation Data Inspector to compare the executable program results with the simulation results.
In the Simulation Data Inspector, inspect the results of your executable
Run 2: rtwdemo_secondOrderSystem.
Select the data runs that you want to compare. For this example, from the
Baseline list, select
rtwdemo_secondOrderSystem. From the Compare
to list, select
In the upper-right corner of the Simulation Data Inspector, click Compare.
The Simulation Data Inspector indicates that the output for
Force: f(t):1 from the
executable program code is out of tolerance from the simulation data output.
To see a plot of the results for
X, under File
Comparisons, select the row for
Inspect the comparison plot for
Force: f(t):1. Under
File Comparisons, select the row for
Determine whether the numerical discrepancies are significant by
specifying an absolute relative tolerance value. For this tutorial, set
Global Abs Tolerance to
Then, click Compare. The comparisons for
Force: f(t):1 are within
For more information,about numerical consistency verification and tolerances, see Numerical Consistency of Model and Generated Code Simulation Results.
Next, tune a parameter during program execution.