Guy on Simulink

Simulink & Model-Based Design

Where Does That Variable Come From?

Most Simulink models use workspace variable to define the important parameters. For example, setting the gain value to K and then defining K in the workspace. I wrote aboutinitializing these parameters in the base workspace在最近的一篇文章中。您是否曾经注意到这些参数有很多来源?K的值可能在基本工作区中,也可能在模型工作区中。K的来源甚至可以戴上面具。

万博1manbetxSimulink通过在使用该变量的块上方的工作区中搜索来确定变量的值。从块开始,它搜索每个掩码工作区,直到达到模型的根部。万博1manbetxSimulink分别搜索模型工作区和基本工作区。这个过程是分层符号分辨率,在这篇文章中,我将演示这些规则,这些规则可以确定Simulink如何解决变量的值。万博1manbetx

An Example Model

为了说明分层符号分辨率的概念,让我们使用一个简单的模型(在这里下载)。该模型除了子系统,恒定块和显示外,什么都没有。常数块是指不同工作区中的变量,并根据层次结构中的位置获取其值。从模型的根部开始,我们找到变量K和M。

可变分辨率仿真模型。万博1manbetx

Look in the Workspace above the Block

我认为模型工作区是模型的根源。模型工作区是搜索K和M的第一个地方。我使用Model Explorer查看模型工作区的内容。

Model explorer showing the model workspace.

我们找到了K,但是M不在模型工作区中。层次结构中的下一个工作区是基本工作区。模型资源管理器便利地显示了反映模型层次结构的树。

模型资源管理器显示基本工作空间。

蒙版工作区

Masked subsystems introduce mask workspaces in the model hierarchy. If the block is in a masked subsystem, it first evaluates in the mask workspace then works its way up through the hierarchy until it reaches the root of the model. Here is the Top subsystem.

Top subsystem, top subsystem mask and the contents of the system.

The mask dialog initializes the variable m with a value of 3000. The variable k is also appears at this level of the model, but resolves to the variable defined at the model workspace level.

子系统从其上下文继承变量

由于分层符号分辨率,子系统从其上下文继承了变量。底部子系统是指K,它来自其面具。它也指m,在顶部面具中解决。如果底部子系统是模型的根源,则M将解析为基础工作区。

底部子系统,底部子系统掩码和系统的内容。

此行为可以使相同的库块根据其父系统的行为不同。例如,摆子系统可能会因其父系统的重力(G)继承加速度。这些母体系统可以为不同环境定义变量。

一个子系统层次结构,该层次结构将允许基于上下文继承变量G。

Controlling Hierarchical Resolution

You can control the resolution of variables in your subsystem by setting the Permit hierarchical resolution parameter in the subsystem parameters (right click on the subsystem and select Subsystem parameters…).

Subsystem parameters, Permit hierarchical resolution.

默认设置为All并为您提供上面描述的行为。如果您不希望变量解析为子系统上方层次结构中定义的符号,则可以将其更改为None。TheExplicitOnlysetting controls resolution of signal and state names by only resolving objects that have been set to resolve explicitly.

模型参考层次结构呢?

层次符号分辨率达到模型的根部时会停止。模型参考层次结构不被视为分层符号分辨率的一部分。任何模型都必须能够单独定义自己,或者作为较大模型参考层次结构的一部分。可以通过模型参考参数将变量向下传递到模型工作区。有关此的更多信息,请参见有关使用模型参数

Now it’s your turn

If you program in M-code than you might see discussion as similar to the way variables are resolved in nested functions of an M-file. Do you take advantage of hierarchical symbol resolution? Leave acomment hereand tell us how.

|

Comments

要发表评论,请单击here登录您的数学帐户或创建一个新帐户。