Guy on Simulink

Simulink & Model-Based Design

子系统参考和测试线束

如果你错过了,就在我写的 this post introducing the Subsystem Reference 。我真的很喜欢这个功能,它允许您只需将子系统的内容存储在单独的文件中。
Since its initial release in R2019b, a lot of enhancements have been made to the Subsystem Reference and today I want to highlight one I find particularly useful: 测试线束

挑战

一个建议我总是developi给用户ng Simulink models is to try keeping the model in an "updatable" state as much as possible. This mostly means doing 更新图 经常(快捷方式: Ctrl+D )。这样,如果你弄错了,你会很快收到描述错误的错误。没有那个,如果在尝试更新模型之前进行多次更改,则错误消息可能会更难以调试,因为可以存在多个与相互相关的问题的组合。
A Reference Subsystem can be edited in two ways, and both have caveats regarding the above suggestion:
  • 编辑独立:由于子系统文件没有完整的配置集,因此无法在独立子系统上执行更新图。
  • 在模型中编辑实例:In a model, it is possible to edit a Subsystem and hit Ctrl+D to validate your changes. One possible challenge with that approach is that, if the model is large and contains many blocks around the modified Subsystem, performing an update diagram might take time.
让我们看看测试线束如何帮助。

创建默认的测试线束

Starting in MATLAB R2020b, the Subsystem tab of a Subsystem Reference file has a new Test Harness section allowing you to create test harnesses:
I am not going to describe in this post why it is always a good idea to create test harnesses for models and subsystems, you can visit the documentation page introducing test harnesses 阅读更多关于该主题的更多信息。
在这篇文章中,我要指出的是,通过测试线束,我们现在有一个上下文,其中可以模拟子系统。

用测试线束更新

Once a Test Harness has been added to a Subsystem file, the 用测试线束更新 动作变得可用,并且与模型中的相同快捷方式相关联( Ctrl+D )。
这意味着当您编辑子系统独立时,您将能够经常击中Ctrl + D并将子系统保留在可更新状态。在引擎盖下,我们将使用测试线束完成更新图,因此如果没有错误,则不必明确打开测试线束。
If there is an error, it will be reported in the Diagnostics Viewer with hyperlinks to the problematic blocks in the context of the harness.

Simulate With Test Harness

In a similar manner, we also added a " 用测试线束运行 “ToolStrip按钮。使用此按钮,使用默认线束模拟子系统,您可以在模拟数据检查器中可视化记录数据。

Now it's your turn

您是否利用子系统参考的测试线束?如果是,您是否利用了那些以确保您的子系统保持“可更新”并验证仿真结果在默认的测试线束中?
Give this feature a try and let us know what you think in the comments below.
|

Comments

要发表评论,请点击here要登录您的MathWorks帐户或创建新的。