[openrtm-users 00198] Re: [openrtm-users 00196] Re: onActivated でのerror

Ando Noriaki n-ando @ aist.go.jp
2007年 9月 7日 (金) 19:24:44 JST


清水様

安藤です

今手元にUML2.0の仕様しかない(最新は2.1.1?)ので申し訳ないですが。。。


UML Superstructure Specification, v2.0, p.555より

まずは遷移条件ですが、
A transition is enabled if and only if:
• All of its source states are in the active state configuration.
• One of the triggers of the transition is satisfied by the event
(type) of the current
 occurrence. An event satisfies a trigger if it matches the event
specified by the
 trigger. In case of signal events, since signals are generalized
concepts, a signal
 event satisfies a signal event associated with the same signal or a
generalization
 thereof.
• If there exists at least one full path from the source state
configuration to either
 the target state configuration or to a dynamic choice point in which all guard
 conditions are true (transitions without guards are treated as if
their guards are
 always true).

最後の項目にもあるように、guardがtrueの場合に遷移が有効になります。
次にガードについてですが、p.556に次のように書いています。

Guards
In a simple transition with a guard, the guard is evaluated before the
transition is
 triggered.
In compound transitions involving multiple guards, all guards are
evaluated before a
 transition is triggered, unless there are choice points along one or
more of the
 paths. The order in which the guards are evaluated is not defined.

ガードの評価は常に遷移の前に行われます。
p.557より
Once a transition is enabled and is selected to fire, the following
steps are carried
 out in order:
• The main source state is properly exited.
• Behaviors are executed in sequence following their linear order along the
segments of the transition: The closer the behavior to the source
state, the earlier
 it is executed.
• If a choice point is encountered, the guards following that choice point are
evaluated dynamically and a path whose guards are true is selected.
• The main target state is properly entered.

> 状態遷移について不明な点があったので教えて下さい.
>
> > OMGのRTC Specificationのステートマシン図でも、
> > ACTIVE状態からERROR状態への遷移のガード条件が、
> > [ReturnCode_t==ERROR]となっているので、
> > on_activated が ERROR のとき、直ちに遷移のトリガーがかかり
> > on_deactivated、on_abortingの順で実行されるものと思います。
>
> この説明によると,ACTIVE状態からERROR状態に遷移するときは,
> ERROR状態のentry関数の前にACTIVE状態のexit関数が呼ばれ
> なければいけないということでしょうか?
> それならば,onDeactivatedでエラーが起こった場合でも,
> onDeactivatedがまた呼ばれなければいけないということに
> なってしまい,なんかおかしな感じがします.

3つの場合に分けて考えてみます。

1. on_activatedがエラーの場合
 a) 遷移のガード条件が評価される
 b) ERRORへのガード条件がtrueであるので遷移する
 c) ACTIVE状態から出る。すなわち、on_deactivatedが実行される
 d) 遷移のアクション on_abortingが実行される
 e) ERRORへの遷移を完了する
※on_activatedが実行された時点では、状態はACTIVEなので、出るときには
  必ずon_deactivatedが実行されるはず。

2. on_executeがエラーの場合
 a) 遷移のガード条件が評価される
 b) ERRORへのガード条件がtrueであるので遷移する
 c) ACTIVE状態から出る。すなわち、on_deactivatedが実行される
 d) 遷移のアクション on_abortingが実行される
 e) ERRORへの遷移を完了する

3. on_deactivatedがエラーの場合
すなわち、deactivateがコールされ、遷移のトリガがかかる。
ガードはトリガの前に評価されており、on_deactivatedの戻り値は
対象にならない。したがって、
 a) ACTIVE状態から出る。すなわち、on_deactivatedが実行される
 b) 遷移のアクションはないのでなにもしない
 c) INACTIVEへの遷移を完了する

以上、UMLの解釈に従えば、このような動作になるように思います。

ただし、現在の実装ではon_deactivatedの戻り値をチェックして、
OKでなければERRORへ遷移するようになっていますが、
上の解釈が正しいとすれば、これはバグになりますね。


> RTMのHPの状態遷移図
> http://www.is.aist.go.jp/rt/OpenRTM-aist/html/E3839EE3838BE383A5E382A2E383AB/RTCE38397E383ADE382B0E383A9E3839FE383B3E382B0E585A5E99680.html
> では,それぞれの状態にentry, do, exitの関数が存在し,
> そのうちのどれかがRTC_OK以外を返した場合に,
> 即座に状態遷移が起こるように見えます.
> ということは,ACTIVE状態のentry, do, exit
> のどれかがエラーとなった場合,
> onDeactivated(ACTIVE状態のexit関数)は呼ばれずに,
> onAborting(ERROR状態のentry関数)が呼ばれるような
> 気がするのですがどうでしょうか?

少なくとも、exitのアクションが記述されている限りは、
その状態から出るときはexitアクションが必ず呼ばれるはずです。

p.533にこう書いてあります。
exit: Behavior[0..1]
An optional behavior that is executed whenever this state is exited
regardless of
 which transition was taken out of the state. If defined, exit actions
are always
 executed to completion only after all internal activities and
transition actions have
 completed execution.


ただし、これらはあくまでUMLの解釈の話なので、この遷移で問題がある場合は、
ステートマシン図を書きなおす必要があります。

ただ、私としてはACTIVE状態から出るとき必ずon_deactivatedが実行されるのは
自然だと思います。
ちなみに、0.2.0でもACTIVE状態から出るときは必ず、
rtc_active_exitが呼ばれるような実装になっていたと思います。


-- 
安藤慶昭@独立行政法人産業技術総合研究所 研究員
                   知能システム研究部門 タスクインテリジェンス研究グループ
                   〒305-8568 茨城県つくば市梅園1-1-1 中央第2
                   TEL: 029-861-5981 FAX: 029-861-5971
                   n-ando @ aist.go.jp, n-ando @ ieee.org




openrtm-users メーリングリストの案内