Fork me on GitHub
Tutorials / Examples / W3C Microwave Parallel

W3C Microwave Parallel

Ported from Alex Zhornyak's SCXML tutorial collection.

This ports the W3C microwave oven parallel example from Alex Zhornyak's SCXML tutorial collection. The statechart separates the oven engine from the door region and uses the SCXML In()predicate to coordinate them.

0
sec
Power
on
Mode
off
Door
closed
Timer
0 / 5

SCXML source

<scxml datamodel="ecmascript"
       initial="oven"
       name="ScxmlMicrowaveOwenParallel"
       version="1.0"
       xmlns="http://www.w3.org/2005/07/scxml">
  <datamodel>
    <data expr="5" id="cook_time"/>
    <data expr="true" id="door_closed"/>
    <data expr="0" id="timer"/>
  </datamodel>

  <parallel id="oven">
    <state id="engine">
      <initial>
        <transition target="off"/>
      </initial>

      <state id="off">
        <onentry>
          <assign expr="0" location="timer"/>
        </onentry>
        <transition event="turn.on" target="on"/>
      </state>

      <state id="on">
        <transition event="turn.off" target="off"/>
        <transition cond="timer &gt;= cook_time" target="off"/>

        <initial>
          <transition target="idle"/>
        </initial>

        <state id="idle">
          <transition cond="In('closed')" target="cooking"/>
        </state>

        <state id="cooking">
          <transition cond="In('open')" target="idle"/>
          <transition event="time">
            <assign location="timer" expr="timer + 1"/>
          </transition>
        </state>
      </state>
    </state>

    <state id="door">
      <initial>
        <transition target="closed"/>
      </initial>

      <state id="closed">
        <transition event="door.open" target="open"/>
      </state>

      <state id="open">
        <transition event="door.close" target="closed"/>
      </state>
    </state>
  </parallel>
</scxml>