对 Boost.statechart 中完成的所有正交状态做出反应

发布于 2024-11-14 15:43:49 字数 863 浏览 6 评论 0原文

我正在开发一个基于状态机的机器人控制程序。虽然该程序使用 Qt 状态机框架,但我还尝试使用 Boost.statechart (BS) 来实现它作为理论练习和学习/评估库的方法。

在 Qt 版本中,我在多个地方使用了以下模式:复合状态具有并行嵌套子图,每个子图最终达到最终状态。当所有并行子状态完成时,父状态发出“finished()”信号,这导致机器转换到下一个顶级状态。例如(注意:伪图):

Idle -calibRequest-> Calibrate( calibrate_camera | calibrate_arm ) -finished-> Idle

calibrate_* 状态又在其内部有嵌套状态,如 S -trigger[caliblated?]->; F 其中 F 是最终状态。当两个 calibrate_* 状态达到各自的 F 状态时,finished 信号会导致状态机转换为 Idle

Qt 的并行子状态类似于 BS 的正交嵌套状态。起初我以为“终止”是 BS 与最终状态的类似物,但事实上并非如此。它更像是“终止状态机,除非仍然有一些正交的东西要去某个地方”——一旦终止所有正交状态,父状态也会终止,没有任何机会传输。在终止时发布事件也没有帮助,因为没有可以将这些事件传递到的状态。

我最终实现了“最终状态”,它在达到时发布通知事件,并在父状态中对此事件做出反应 - 检查所有正交状态是否已达到其最终事件并然后进行转换。这基本上是 Qt 状态机方法的重新实现,但每次我需要这种模式时都必须重做。但也许我只是太习惯了实现这种效果的一种方法,以至于我看不到其他选择?

I'm working on a robot control program that is based on a state machine. While the program uses Qt State Machine Framework, I also attempted to implement it using Boost.statechart (BS) as a theoretical exercise and a way to learn / evaluate the library.

In Qt version I used the following pattern in several places: a compound state has parallel nested sub-graphs, each of which eventually reaches a final state. When all parallel sub-states finish, the parent state emits "finished()" signal, which causes the machine to transit to the next top-level state. E.g. (Beware: pseudo diagram):

Idle -calibRequest-> Calibrate( calibrate_camera | calibrate_arm ) -finished-> Idle

and calibrate_* states in turn have nested states inside them like S -trigger[calibrated?]-> F where F is a final state. When both calibrate_* states reach their respective F states finished signal causes the state machine to transit into Idle.

Qt's parallel child state are analogous to BS's orthogonal nested states. At first I though "termination" was BS's analogue to final states, but in fact it isn't. It's more like "terminate the state machine unless there is still some orthogonal thing going somewhere" - once you terminate all orthogonal states the parent state terminates as well without any chance to transit. Posting events upon termination doesn't help either since there is no state that these events could be delivered to.

I ended up implementing "final states" which post a notification event when reached and reacting on this event in the parent state - checking if all orthogonal states have reached their final events and transiting then. Which is basically reimplementation of Qt State Machine's approach, but which has to be redone each time I need this pattern. But may be I'm just so used to one way of achieving this effect that I don't see an alternative?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文