从内部原子子图访问Simulink函数

发布于 2025-01-28 06:27:20 字数 641 浏览 3 评论 0原文

由于远远超出了我的控制,我现在一直在做MATLAB/SIMULINK/stateFlow工作。我已经完成了坡道训练,并且我已经鄙视做任何基于文本的编程语言的常见且容易的事情是多么的直觉。

因此,这是我的问题:我正在尝试创建可以像功能一样重复使用的状态流子图,例如在请求SPI总线的一系列响应时要采取的一系列步骤。我希望能够在同一父态流图中的其他子图中使用此子图。到目前为止,我的研究使我成为了原子科。

问题是,我的子图依赖于许多Simulink函数,而Simulink功能又呼叫S功能与STM32目标进行通信。我可以在根状态流图中使用Simulink函数来制作子图,这是没有问题的。但是,当我将子图转换为原子次子图时,它无法再检测到simulink函数,从而为我在子图中为它们提供了错误。

所有这些我都在图书馆内部作为特定芯片的常见代码,我们在许多内部电路板上使用。作为最后的皱纹,整个过程都在更大的系统中使用,并使用状态之间的“ After()”过渡,以便RTOS可以做其他事情。综上功能”。

  • 有什么方法可以从原子能内部访问Simulink函数?
  • 还有其他方法可以重复使用函数之类的状态流图,以便我可以更新根图,而无需在多个位置修改相同的副本/粘贴代码?
  • 我也无法使用图形函数,因为这些图具有循环,显然您无法在图形函数中回溯。

For reasons far outside my control, I have now been thrust into doing MATLAB/Simulink/Stateflow work. I've done the On-Ramp training, and already I despise how unintuitive it is to do things that are just common and easy in any text-based programming language.

So here's my issue: I am trying to create Stateflow subcharts that I can reuse like a function, like a series of steps to take when requesting a series of responses from an SPI bus. I want to be able to use this subchart from within other subcharts in the same parent Stateflow diagram. My research has so far led me to Atomic Subcharts.

The problem is, my subchart relies on a number of Simulink Functions, which in turn call S-Functions to communicate with an STM32 target. I can make the subchart, no problem, with the Simulink Functions in the root Stateflow diagram. But when I convert the subchart into an Atomic Subchart, it can no longer detect the Simulink functions, giving me errors in the subchart for them.

All of this I am doing inside of a library as common code for a particular chip we use on a number of in-house circuit boards. As a final wrinkle, this whole thing is being used inside a much larger system and uses the "after()" transition between states so that the RTOS can go do other things. As far as I am aware, I cannot do the same thing inside of a Simulink or MATLAB function and HAVE to do this in Stateflow, which means I can't just make a normal "do all SPI reads" function but need a "Stateflow function".

  • Is there any way to access Simulink Functions from inside an Atomic Function?
  • Is there any other way to reuse a Stateflow diagram like a function, so that I can update the root diagram without having to modify the same copy/pasted diagram code in multiple places?
  • I also cannot use graphical functions because these diagrams have loops, and apparently you can't backtrack inside of a graphical function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2025-02-04 06:27:20

因此,我在解决这个问题时找到了一个答案,它具有比我更多的状态流程体验。他提到了“同时运行状态”的想法。

您要做的是,在根状态下,将正常状态分为一个子图。然后,对于要像函数一样调用的任何可重复使用的代码,将其置于空闲状态的独立状态计算机。然后,您可以在主要状态下声明本地事件,以将“函数”状态从其空闲状态移动,并让您的主要状态等待“函数”返回其空闲状态。

您的主要状态中的“函数呼叫”将始终具有2个状态,因为您需要“函数”处于闲置状态,然后再等到它返回其闲置状态,但是如果您有一个足够复杂性的子图比试图在多个子图中复制和粘贴相同的行为并以后必须修改相同的行为要紧凑得多。另外,您将获得类似功能的行为,即只需修改您的“功能”子图即可修改状态流图上的所有行为。

可以在此处找到有关如何创建并行运行状态的信息:

https:https:// wwwwww .mathworks.com/help/stateflow/gs/parallelism.html
https://wwwww.mathworks.coms.com/help/help/help/stateflow/gs/gs/events。 html

So I found an answer while working through this problem with more Stateflow experience than me. He mentioned the idea of "concurrently running states".

What you do is, at the root state, group your normal state into a subchart. Then for any reusable code you want to call like a function, make that a separate state machine with its own substates that defaults to an Idle state. You can then declare a local event in your main state to move the "function" state from its idle state, and have your main state wait for the "function" to return to its idle condition.

Your "function calls" in your main states are going to always have 2 states as you want for the "function" to be in its idle state, and then wait again until it returns to its idle state, but if you've got a subchart of sufficient complexity, this is a lot more compact than trying to copy and paste the same behavior in multiple subcharts and having to modify them later. Plus, you get the function-like behavior of only having to modify your "function" subchart to modify the behavior all across your stateflow diagram.

Information about how to create parallel running states can be found here:

https://www.mathworks.com/help/stateflow/gs/parallelism.html
https://www.mathworks.com/help/stateflow/gs/events.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文