【问题标题】:boost MSM how to define transition between two sub-states?boost MSM 如何定义两个子状态之间的转换?
【发布时间】:2018-04-04 04:49:22
【问题描述】:

我正在使用 Boost 1.64.0 MSM 库来生成分层状态机。为了测试转换机制,我实现了一个这样的状态机

+------------------------------------------------+
|                       S                        |
|   +-------------+          +-------------+     |
|   |      S1     |          |      S2     |     |
|   |  +-------+  |          |  +-------+  |     |
|   |  |  S11  |  |          |  |  S21  |  |     |
|   |  +-------+  |          |  +-------+  |     |
|   +-------------+          +-------------+     |
|                                                |
+------------------------------------------------+

那么如何定义从S11到S21的转换,根据the same situation described in wiki转换执行顺序应该是'exit S11' -> 'exit S1' -> 'enter S2' -> 'enter S21'。

【问题讨论】:

    标签: uml state-machine boost-msm


    【解决方案1】:

    根据文档https://www.boost.org/doc/libs/1_66_0/libs/msm/doc/HTML/ch03s02.html#d0e875

    • 只能显式进入目标的子状态 但不是子子状态。
    • 无法显式退出。必须使用出口点。

    所以你不能明确退出 S11。

    您可以使用退出点伪状态代替显式退出。而且我建议使用入口点伪状态而不是显式入口。

    这里是入口点伪状态的示例代码

    http://redboltz.wikidot.com/entry-point-pseudo-state

    和出口点伪状态。

    http://redboltz.wikidot.com/exit-point-pseudo-state

    【讨论】: