Main Content

Real-Time Model Preparation

Obtaining reference results, performance optimization

Preparing a Simscape model for real-time involves iteratively balancing the performance and fidelity to produce accurate results at a small enough cost and time step for the target machine. Begin by obtaining reference results from your model. When your model produces accurate results compared to the reference results using a fixed-step solver, you can attempt to deploy your model to the real-time target. Take these steps as needed to balance performance and fidelity:

  • Use ideal or system-level blocks and ideal parameterizations in place of more complex blocks and parameterizations.

  • Remove sources of fast dynamics.

  • Remove sources of numerical stiffness.

  • Remove sources of zero-crossings.

  • Use the Partitioning Solver.

  • Partition the model.

  • Minimize solver iterations.

  • For FPGA deployment, reduce sources of modes.

To analyze solver performance for fast dynamics and numerical stiffness, use the Solver Profiler tool. When you are ready to convert to fixed-step, fixed-cost, use the simscape.getLocalSolverFixedCostInfo function to determine how many nonlinear iterations to perform.

Tools

Solver ProfilerIdentify solver performance bottlenecks

Functions

simscape.getLocalSolverFixedCostInfoDetermine iteration requirement when transitioning to fixed cost (Since R2021b)

Topics

Fixed-Step Fixed-Cost Setup

Performance Optimization

  • Reduce Zero Crossings
    Eliminate components that cause zero crossings to increase the minimal step-size for fixed-step simulation and to make your Simscape model real-time capable.
  • Increase Simulation Speed Using the Partitioning Solver
    Improve performance by using the Simscape Partitioning solver to convert a large system of equations into several smaller systems of equations that are easier to solve.

FPGA Deployment

Generic Platforms

  • Requirements for Using Alternative Platforms
    Follow the recommendations for minimum hardware, software, and compiler specifications to deploy your Simscape model for hardware-in-the-loop (HIL) simulation using a custom standalone application.
  • Embedded and Generic Real-Time Resources
    Simulink® Coder™ and Embedded Coder® use system target files (STFs) to generate code for interfacing with specific real-time operating systems.

Featured Examples