主要内容

Improving Speed and Accuracy

为什么速度和准确性对于实时模拟很重要

Speed and accuracy are the determining factors for making your model real-time capable. Your model is real-time capable if it satisfies both of these conditions when you simulate it on your particular target hardware:

  • 没有超支。

  • 模拟结果符合您的准确性标准。

Speed is objective. The real-time clock determines whether your model is fast enough for real-time simulation. For each step that your solver takes, your real-time hardware system tracks the time that it takes to complete these processing tasks:

  • 执行模拟。

  • 过程输入和输出。

  • Perform general computer tasks.

An overrun occurs when, for any time step, the time that it takes your system to complete the processing tasks exceeds the real-time limit for the tasks. If your target machine reports any overruns when you use it to simulate your model, your model is not fast enough for real-time simulation.

Your Simscape™ model is accurate if it produces results that agree with the empirical and theoretical data that are the basis for your model. Accuracy is more subjective when the foundation and simulation data are similar, but are not in absolute agreement. To determine if your model is accurate enough for real-time simulation when the data do not match perfectly, consider these questions:

  • Is the model representing the phenomena that you want it to measure?

  • 它是否正确地代表了这些现象?

  • If you plan to use your model to test your controller design, is the model accurate enough to produce results that you can rely on for system qualification?

The only way to test whether your model is real-time capable is to run it on your actual real-time target hardware using fixed-step, fixed-cost solvers. You can, however, estimate whether the model is both fast and accurate enough for real-time simulation by analyzing the results from desktop simulation. To estimate whether your model is real-time capable, seeDetermine Step SizeEstimate Computation Costs

如果来自桌面仿真的分析表明您的模型可能不是实时能力的,请在将模型部署到实时目标机器之前提高模型速度或准确性。提高模拟的速度倾向于降低准确性,相反提高准确性会降低速度。为了使模型实时能够,请在速度和准确性之间保持平衡。

平衡速度和准确性

Simulation speed and accuracy correlate to your choices for:

  • 模型保真度和范围

  • 实时硬件计算能力

  • 求解器样品时间(步长)和迭代次数

试图提高模拟速度,有可能以准确性为代价:

  • 降低模型保真度或范围。

  • Increase sample time.

  • Decrease the number of solver iterations.

To try to increase simulation accuracy, potentially at the expense of speed:

  • 增加模型保真度或范围。

  • 减少样本时间。

  • 增加求解器迭代次数。

To try to increase both accuracy and speed, or either one without sacrificing the other, increase computing power. To increase computing power, use a faster real-time processor or compute in parallel.

The type of solver that you specify also affects simulation speed and accuracy. For fixed-step simulation, Simscape local solvers are faster and as accurate as Simulink®global solvers. Implicit solvers are faster, but less accurate than explicit solvers. However, the numerical stiffness of the network is also a determinant for deciding whether to use an implicit solver or an explicit solver. Explicit solvers yield more accurate results for numerically stiff networks.

For more information on how model complexity affects speed and accuracy, see消除需要密集计算的效果。有关求解器配置如何影响速度和准确性的更多信息,请参见优化本地和全局求解器配置

模型复杂性和求解器设置可能没有组合可以使您的模型实时能够。如果模拟未在目标机器上实时运行,或者准确性不可接受,请考虑这些选项以提高速度和准确性:

消除需要密集计算的效果

如果您的桌面仿真分析表明您的模型可能不足以实时模拟,请消除需要密集计算的效果。确定模型中引起昂贵效果的元素,例如不连续性和快速变化,这些元素往往会减慢模拟。

引起不连续性的元素包括:

  • 硬停止或反弹

  • Stick-slip friction

  • Switches or clutches

Elements with small time constants that cause rapid changes include:

  • Small masses attached to stiff springs with minimal damping

  • 电路低电容,电感和电阻

  • 液压电路,可压缩体积小

To eliminate or modify the elements that are responsible for the effects that slow down your simulation, use these approaches:

  • Replace nonlinear components with linearized versions.

  • Replace complex equations with lookup tables for their solution.

  • Replace complicated components with simplified models.

  • 通过过滤器,延迟和其他技术平滑不连续的功能(步骤更改)。

优化本地和全局求解器配置

您还可以通过求解器规格来影响模拟的速度和准确性。实时目标机提供的准确性水平不一定与单个模型中所有网络的特定步长相关。实时目标机器可以为模型中的简单网络提供准确的结果,但对于更复杂的网络而言,结果不准确。利用能够为SIMSCAPE模型中每个网络指定不同求解器配置的能力。为了帮助您实时模型,请分别配置固定步骤的全局求解器和每个本地求解器。

For information on solver options and determining the solvers that help to make your Simscape model real-time capable, seeSolvers for Real-Time Simulation

升级目标硬件

当使用相同的步长以模拟相同的模型时,不同的目标可以给出不同的准确性。您可以使用更快的实时目标计算机加快或提高实时仿真的准确性。

并联模拟系统的部分

另一种方法提高速度while maintaining accuracy is to configure your model to evaluate multiple physical networks in parallel. You can partition your model if the networks are not dependent upon one another. Work with and experiment with your model, the generated code, and the real-time target machine to use this approach.

Related Examples

More About