Main Content

Real-Time Code Generation and Deployment Process

When you determine that your model is ready to for real time, use the real-time simulation process to simulate your model in real time. The flowchart demonstrates an example real-time simulation process. Use a fixed-cost solver to simulate the model and check whether the results and execution time are acceptable. Like the model preparation process, the fixed-cost process may require several iterations of adjusting step size and number of iterations, and you may need to return to the model preparation process if you are unable to produce acceptable results.

If you are performing HIL simulation to test your controller:

  • Configure your controller.

  • Connect your controller to the real-time computer.

Perform Hardware-in-the-Loop Simulation

Generate, Download, and Execute Code

Use Simulink® Real-Time™ to:

  • Generate and compile code on the development computer.

  • Download the real-time application to the target computer.

  • Execute the real-time application remotely from the development computer.

For information, see Generate, Download, and Execute Code.

Evaluate Accuracy

Compare the results from the simulation on the target computer to your reference results. Are the reference and modified model results the same? If not, are they similar enough that the empirical or theoretical data also supports the results from the simulation of the modified model? Is the modified model representing the phenomena that you want it to measure? Is it representing those phenomena correctly? If you plan on using your model to test your controller design, is the model accurate enough to produce results that you can rely on for system qualification? The answers to these questions help you to decide if your real-time results are accurate enough.

Evaluate Speed

To find out if your simulation generates an overrun, examine the task execution time (TET) report that Simulink Real-Time generates for the simulation.

Return to the Real-Time Model Preparation Workflow

Your model is not real-time capable if simulation on your real-time target machine generates an overrun or produces results that do not match your reference results closely enough. To make your model real-time capable by adjusting model fidelity, return to the real-time model preparation or real-time simulation workflow.

Adjust the fidelity or scope of your model, and then step through the other processes and decisions in the real-time model preparation workflow. Iterate on adjusting, simulating, and analyzing your model until it is fast and accurate enough for you to perform the real-time simulation workflow. Perform the real-time simulation workflow, and then attempt the hardware-in-the-loop simulation workflow again. For information, see Model Preparation Process and Fixed-Cost Simulation Process.

Return to the Real-Time Simulation Workflow

Your model is not real-time capable if simulation on your real-time target machine generates an overrun or produces results that do not match your reference results closely enough. To make your model real-time capable by adjusting the simulation solver settings, return to the real-time simulation workflow.

Perform the real-time simulation workflow, and then attempt the hardware-in-the-loop simulation workflow again. For information, see Fixed-Cost Simulation Process.

Insufficient Computational Capability for Hardware-in-the-Loop Simulation

Your real-time target machine can lack the computational capability for running your model in real time. If your model fails to run in real time or produces unreliable results on your target machine after multiple iterations of the real-time workflows, consider simulating parts of the system in parallel. To learn more, see Simulating Parts of the System in Parallel.

Manage Model Variants

Variant blocks allow you to create a single model that caters to multiple variant requirements. Such models have a fixed common structure and a finite set of variable components. The variable components are activated depending on the variant choice that you select. Thus, the resultant active model is a combination of the fixed structure and the variable components based on the variant choice. The use of variant blocks in a model helps in reusability of the model for different conditional expressions called variant choices. For more information and examples, see Implement Variations in Separate Hierarchy Using Variant Subsystems.

However, you cannot simulate on real-time target hardware using code that does not specify default variant choices. Before you generate code for real-time simulation, use the Variant Manager to identify variant blocks in your model and to manage the variation points that are modeled using those blocks. To learn how to use the variant manager, see Variant Manager for Simulink.

Limitations

Simscape™ does not support conditional compilation for model variants.

Troubleshooting

If your real-time application generates an overrun, to improve application execution time:

  • Use the processes described in Model Preparation Process, Fixed-Cost Simulation Process, and Real-Time Code Generation and Deployment Process.

  • Run the Simulink Real-Time Performance Advisor Checks. Use the Execute real-time application activity mode in Performance Advisor, which includes checks specific to physical models. The mode helps you optimize your Simscape model for real-time execution. The checks are organized in folders. The checks in the Simscape checks folder are applicable to all physical models. Subfolders contain checks that target blocks from add-on products such as Simscape Electrical™ and Simscape Driveline™.

    To access the checks:

    1. Open the Performance Advisor. On the Debug tab, click the Performance button.

    2. In the Performance Advisor window, under Activity, select Execute real-time application.

    3. In the left pane, expand the Real-Time folder, and then the Simscape checks folder.

    4. Run the top-level Simscape checks. If your model contains blocks from an add-on product, also run the checks in the subfolder corresponding to that product.

    For more information, see Troubleshoot Unsatisfactory Real-Time Performance (Simulink Real-Time).

A Simulink Real-Time simulation can also fail due to development and target computer issues, changes in underlying system software, I/O module issues, and procedural errors. To address these issues, follow the workflow in Troubleshooting Basics (Simulink Real-Time). For more information, see Troubleshooting in Simulink Real-Time (Simulink Real-Time).

Related Examples

More About