In this step of the tutorial, you verify that when executed, the code is numerically
equivalent to the algorithm modeled in Simulink®. You use a test harness model to simulate rtwdemo_roll
in
normal mode and in SIL mode, then compare the simulations by using the Simulation Data
Inspector.
To test generated code, you can run software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations. A SIL simulation compiles and runs the generated code on your development computer. A PIL simulation cross-compiles source code on your development computer. The PIL simulation then downloads and runs the object code on a target processor or an equivalent instruction set simulator. You can use SIL and PIL simulations to:
Verify the numeric behavior of your code.
Collect code coverage and execution-time metrics.
Optimize your code.
Progress toward achieving IEC 61508, IEC 62304, ISO 26262, EN 50128, or DO-178 certification.
Model rtwdemo_roll_harness
references the model-under-test,
rtwdemo_roll
, through a Model block. The harness model
generates test inputs for the referenced model. You can easily switch the
Model block between the normal, SIL, or PIL simulation modes.
Open model rtwdemo_roll_harness
. If you closed your copy of model
rtwdemo_roll
, reopen it.
In the rtwdemo_roll_harness
model, right-click the
Model block and select Subsystem & Model Reference > Refresh Selected Model Block.
Save a copy of rtwdemo_roll_harness
in the current working
folder.
Open the Configuration Parameters dialog boxes for
rtwdemo_roll_harness
and rtwdemo_roll
.
To run SIL and PIL simulations, on the Code Generation pane, verify that parameter Generate code only is cleared. Do this for both models.
For both models, on the Hardware Implementation pane, expand Device details. Verify that Support long long is selected.
Click OK. Then, save the models.
Run the harness model in normal mode and capture the results in the Simulation Data Inspector.
In the rtwdemo_roll_harness
model, open the Model Data Editor. On
the Modeling tab, click Model Data
Editor.
In the Model Data Editor, select the Signals tab.
Set the Change view list to
Instrumentation
.
In the data table, select all rows.
To configure signals to log simulation data to the Simulation Data Inspector, select a cleared check box in the Log Data column. When you are finished, make sure that all of the check boxes in the column are selected.
Right-click the Model block, Roll Axis Autopilot
.
From the context menu, select Block Parameters.
In the Block Parameters dialog box, for Simulation mode, verify
that the Normal
option is selected. Click
OK.
Simulate rtwdemo_roll_harness
.
When the simulation is done, view the simulation results in the Simulation Data Inspector. If the Simulation Data Inspector is not already open, on the Simulation tab, click Data Inspector.
For the most recent (current) run, double-click the run name field and rename the
run: roll_harness: Normal mode
.
Select Ail_Cmd
to plot the signal.
The SIL simulation generates, compiles, and executes code on your development computer. The Simulation Data Inspector logs results.
In the rtwdemo_roll_harness
model window, right-click the
Roll Axis Autopilot
model block and select Block
Parameters.
In the Block Parameters dialog box, set Simulation mode to
Software-in-the-loop (SIL)
and Code Interface
to Top model
. Click OK.
Exclude external code files from the build process. In the Configuration Parameters
dialog box for model rtwdemo_roll
, set Code Generation > Custom Code > Additional build information > Source files to the default value, which is empty. Save the model.
Simulate the rtwdemo_roll_harness
model.
Minimize the code generation report window for exploration later in this tutorial.
In the Simulation Data Inspector, double-click the run name field and rename the new
run as roll_harness: SIL mode
.
Select Ail_Cmd
to plot the signal.
Reconfigure the build process for model rtwdemo_roll
to include
the external source files roll_input_data.c
and
roll_heading_mode.c
. In the Model Configuration Parameters dialog
box, set Code Generation > Custom Code > Additional build information > Source files to roll_input_data.c roll_heading_mode.c
. Click
Apply, close the dialog box, and save the model.
In the Simulation Data Inspector:
Click the Compare tab.
In the Baseline field, select roll_harness: Normal
mode
.
In the Compare To field, select roll_harness: SIL
mode
.
Click Compare.
The Simulation Data Inspector shows that the normal mode and SIL mode results match. Comparing the results of normal mode simulation with SIL and PIL simulations can help you verify that the generated application performs as expected.
Next, explore ways that you can deploy generated code.