昨天碰到个头大的问题,某个FSM的状态里面使用了TimedDelay,问题是在TimedDelay之前数据能够显示出来,但在TimedDelay之后就没有数据了,即使把TimedDelay的值设置为0.0都无法显示数据。
为什么呢?
经过边查找资料便苦想,终于想通了:
对于FSM本身来说,它跳转的条件是Guard,只要有满足条件立即跳转!而且它不会去考虑某个State里面在做什么其它的事,比如Delay。所以呢,但我们让某个State进行Delay时,可能还没有开始Delay,State就发现目前的条件满足了某个Guard了。立即跳走了,所以那个Delay也真的被无限期Delay了。
怎么解决呢?
其实很简单,当我们让State做事时,总要有个终止的时候,比如最后输出到端口pOut,那么我们在跳转的Guard里面添加一个判断,当pOut接收到数据之后才可以跳转。就OK了。比如在原来条件上加上“ && pOut_isPresent”
问题解决!
另外,在查找资料时,看过ptolemy.domains.de.kernel.DEDirector的文档,里面只有一段话提到TimedDelay,也不知道这个对我解决了问题究竟起到什么样的影响,总之引用如下:
Directed loops of IO ports with no delay will trigger an exception. These are called causality loops. Such loops can be broken with actors whose output ports do not have an immediate dependence on their input ports, such as the TimedDelay actor. Notice that the TimedDelay actor breaks a causality loop even if the time delay is set to 0.0. This is because DE uses a superdense notion of time. The output is interpreted as being strictly later than the input even though its time value is the same. Whether a causality loop exists is determined by the CausalityInterface returned by each actor's getCausalityInterface() method.
没有评论:
发表评论