Guy on Simulink

Simulink & Model-Based Design

Array of Buses and S-Function Builder support

本星期, Navid Rahbariasr. proposed to publish a blog post about support for 公共汽车阵列 被添加到 S-Function Builder 在matlab r2021b中。
这让我意识到我从未在Simulink中覆盖了一系列公共汽车的基础。金宝app因此,本周我们将通过描述如何在MATLAB R2021B中的S函数Builder块中使用的方式来使用创建公共汽车阵列的基础知识。

MATLAB等价物:结构阵列

在MATLAB中,可以使用像代码创建一个结构阵列
另一个等价代码可能是:
让我们看看我们如何在Simulink中做同样的事情。金宝app

创建一系列公共汽车

在Si金宝appmulink中,MATLAB结构的等同物是总线信号。因此,让我们尝试使用矢量连接块创建两个相同的总线信号并将它们连接到数组中,这是更新图之后模型的样子:
如果你熟悉 信号线风格 在Si金宝appmulink中,您可能已经得出结论,即在这里有一些不起作用的东西。出来的两个信号出来的总线创建者1和总线创建者2是公共汽车,但是矢量连接的输出是4个元素的向量,而不是一系列总线。
原因是Simulink可以将总线信号视金宝app为矢量。在这种情况下,Simulin金宝appk决定将总线信号视为矢量是因为它们是虚拟总线。只有非横向总线只能连接到一系列总线上。
要使总线信号非virtual,可以使用 金宝appsimulink.bus.createobject. or the Bus Editor 创建一个 bus object
然后,该总线对象可以在总线创建器块中使用,以指定输出应该是非宽恕的:
and now the signal lines styles are as expected, we are producing an Array of two buses.
Note: If you would like to avoid Simulink treating bus signal as vector and instead prefer getting a warning or an error, look at the diagnostic 公共汽车信号被视为矢量

Nested Array of Buses

Let's extend our example by including the array of buses previously created into a larger bus:
要发生这种情况,新总线对象的元素“z”必须是“总线1”和尺寸2的类型。

访问Matlab功能块和eventflow中的总线数组

当向公共汽车或一系列公共汽车喂食时 马铃薯草Function block or a stateflow图表 ,可以像MATLAB中的结构数组一样访问单个元素:
顺便说一下,如果您尚未注意到,在Matlab R2021B中,MATLAB功能块的代码现在将打开在Simulink画布中而不是MATLAB编辑器。金宝app

访问S-Function Builder中的公共汽车阵列

As mentioned at the beginning of this post, in MATLAB R2021b support for nested arrays of buses has been added to the S-Function Builder block.
Let's replace the MATLAB Function block by the S-Function Builder in the previous model:
For the block to accept the bus signal, we first need to specify the corresponding bus object in the Ports and Parameters panel. Then you can type the C code equivalent to the MATLAB code above in the Outputs section of the S-function Builder app. Note that U0. 是一个指针类型,所以我们需要将其取消引用“ -> “要找到元素。 Also C-Language uses zero based indexing, so the first element of z would be z [0]:
After building the S-Function, you should notice a header file with the bus definitions in the current directory:

Now it's your turn

Are you using arrays of buses? Will you take advantage of this new support in S-function builder to pass arrays of buses to custom C code? Let us know in the comments below.
|

评论

要发作评论,请请此处登录到您的 MathWorks 帐户或创建一个新帐户。