This example shows you how to use Embedded Coder® Support Package for BeagleBone Black™ Hardware for code verification and validation using PIL and External Mode features.
In this example you will learn how to configure a Simulink model to run Processor-In-the-Loop (PIL) and External Mode simulations. In a PIL simulation, the generated code runs on target hardware. The results of the PIL simulation are transferred to Simulink to verify the numerical equivalence of the simulation and the code generation results. The PIL verification process is a crucial part of the design cycle to ensure that the behavior of the deployment code matches the design.
Simulink's External mode feature enables you to accelerate the process of parameter tuning by letting you change certain parameter values while the model is running on target hardware, without stopping the model. When you change parameter values from within Simulink, the modified parameter values are communicated to the target hardware. The effects of the parameter tuning activity may be monitored by viewing algorithm signals on scopes or displays in Simulink.
This example introduces the Simulink code generation and verification workflow by showing you how to:
Configure a Simulink model to run PIL simulations on the BeagleBone Black hardware.
Configure a Simulink model to run External Mode simulation on BeagleBone Black hardware.
We recommend completing Getting Started with Embedded Coder Support Package for BeagleBone Black Hardware example.
This example shows how the automatically generated PIL block can be used for verification. With this approach:
You can verify code generated for subsystems
You must provide a test harness model to supply test vector or stimulus inputs
You must swap your original subsystem with an automatically generated PIL block; you should be careful to avoid saving your model in this state as you would lose your original subsystem
1. Open the PIL Block model. This model is configured for BeagleBone Black hardware. The objective here is to create a PIL block out of the Controller subsystem running on the BeagleBone Black hardware.
2. Enable PIL feature by following the steps below:
3. Create a PIL block for the Controller subsystem by following the steps below:
4. Run PIL simulation:
5. You can switch between the original and PIL block subsystems by double clicking on the Manual Switch block. Double click on the Numerical Differences block to see the difference between the simulated Controller subsystem and the PIL block running on the hardware.
This example shows how you can verify the automatically generated code for a referenced model by running a PIL simulation. With this approach:
You can verify code generated for referenced models
You must provide a test harness model to provide test vector or stimulus inputs
You can easily switch a Model block between normal and PIL simulation mode
1. Open Model Block PIL model. This model is configured for BeagleBone Black hardware. The model contains two Model blocks that both point at the same referenced model. You will configure one of the Model blocks to run in PIL simulation mode and the other in normal mode.
2. Configure and run CounterA Model block in PIL simulation mode by following the steps below:
3. When model starts running, Scope1 displays the PIL simulation output running on the target hardware while Scope2 shows the normal mode simulation output.
This example shows how you can verify the automatically generated code for a top model by running a PIL simulation. With this approach:
You can verify code generated for a top model
You must configure the model to load test vectors or stimulus inputs from the MATLAB workspace
You can easily switch the entire model between normal and PIL simulation mode
1. Open the Top Model PIL model. This model is configured for BeagleBone Black hardware. You will run the model PIL simulation mode.
2. Run the entire model in PIL simulation mode by following the steps below:
3. When the PIL simulation is completed, a logsOut variable is created in the base workspace. The logsOut data contains PIL simulation results. You can access the logged data for signals count_a and count_b using the following commands:
count_a = get(logsOut,'count_a');
count_b = get(logsOut,'count_b');
In this task, you will run a Simulink model in External simulation mode. When you are prototyping and developing an algorithm, it is useful to monitor and tune the algorithm while it runs on hardware. The External mode feature in Simulink enables this capability.
1. Open the External Mode model. This model is configured for BeagleBone Black hardware. You will run the model in External simulation mode.
2. Verify the connectivity parameters for your BeagleBone Black hardware by following the steps below:
If you connected your BeagleBone Black hardware to your host computer via a USB cable, the IP address of your board should be 192.168.7.2. The username and the password shown on the screen shot above shows the default username and password for BeagleBone Black Debian Linux distribution.
3. Select the signals that you would like to instrument. It is recommended that you instrument signals by streaming them to the Simulation Data Inspector rather than by using Scope blocks for the following reasons:
Streaming does not store data in memory, making more efficient use of the memory available on the hardware. Scope blocks store data in buffers before sending the data to the host.
You can stream signals from top models and reference models simultaneously. Scope blocks can only log signals from a top level model.
Note: Data streamed to the Simulation Data Inspector is unaffected by external mode triggers. As a result, external mode parameters such as Duration (ExtModeTrigDuration) and Delay (ExtModeTrigDelay) will have no effect on the data from signals being streamed to the Simulation Data Inspector.
If you have a model with logged signals and only want to stream them, then you can convert the logged signals to streamed signals using the
To stream data from your model into the Simulation Data Inspector:
Select one or more signals in the model.
On the Simulink Editor toolbar, click the Simulation Data Inspector button arrow and select Stream Selected Signals to Data Inspector to mark the signal for streaming.
A streaming badge is shown above the signals in the model that have been marked for streaming.
4. Configure the model for External Mode simulation and start simulation by following the steps below:
In this step, the simulation stop time is set to 'inf' to run the simulation until you explicitly pause or stop the model.
5. Wait for the model to finish getting built and downloaded onto hardware. double click on the Scope block to view the External mode simulation results. Double click the Manual Switch block while simulation is running to change the input source. Double click on the Gain block to change the signal gain. Note that the entire model is running on the hardware while you are viewing the simulation results on your host computer.
If a signal had been selected for streaming to the Simulation Data Inspector, a new simulation run appears in the Runs pane of the Simulation Data Inspector. During simulation, the Simulation Data Inspector button appears highlighted to indicate that new simulation output is available in the Simulation Data Inspector.
6. Stop External mode simulation:
NOTE: At any point during the course of the External mode simulation, you can open the External Mode Control Panel, by following the steps below:
This example introduced the workflow for code verification using target connectivity features PIL and External Mode.