A state-transition diagram (or finite state diagram) is a useful tool to graphically describe the behavior of a system. The diagram describes a system as a collection of distinct operational states and defines events or conditions that trigger a transition from one state to another. In the context of a control algorithm, each state represents a set of commands (or outputs) that the controller is to generate. The controller executes that same command set until a given condition is satisfied. When the condition is met, the controller shifts to a new state where it executes a different command set.
Design Pad G4 provides built-in support to create state-transition diagrams as part of a schema document. A state-transition diagram in Design Pad G4 consists of a set of State Sub-Schema operators interconnected by directed arcs (transitions). State machine operators are found in the Sub-Schema operator menu; transition arcs are created using the state transition wiring tool and clicking from the start state to end state.
Each State Sub-Schema operator is associated with a sub-schema document that executes while the operator is active. Only a single state within a connected state-transition diagram may be active at any instant of time. The system will transition from the active state to another state when a logical condition associated with the transition arc that connects the two states is met. For example, consider a state-transition diagram having two states, A and B, and a transition arc T that connects state A to state B. The system will exit active state A to enter state B when transition T is true.
As indicated above, only a single State Sub-Schema operator within a state-transition diagram may be active at a given time instant. However, a schema may contain multiple disjoint state-transition diagrams that execute concurrently. (A schema may then contain multiple State Sub-Schema operators that are active at the same time, provided that they belong to disjoint state-transition diagrams.)
Each State Sub-Schema operator must be linked to or associated with a schema (.scm) file that contains the desired functional behavior to be executed while the operator is active. The sub-schema file is itself a collection of interconnected graphical operators that may include other State Sub-Schema operators and/or Function Block Sub-Schema operators (which may themselves contain sub-schema operators).
Unlike most operators, the State Sub-Schema operator is not configured through a property sheet. Instead, its configuration is defined by attributes of the linked schema file and through a drop-down menu. This drop-down menu is accessed by right-clicking on the operator icon graphic (i.e., the circle). It contains various commands to manage the operator's link to a schema file. For instance, to link an existing schema file to the operator, select the Link Existing Schema item, and use the File Open dialog to select the desired file.
The schema link is stored as a relative file path to the parent schema. The link can be manually edited by selecting the Edit Schema Link item from the drop-down menu. This command is useful if the schema file is renamed or moved to a different directory outside of the Design Pad G4 environment. The schema link can be removed altogether by selecting the Unlink Schema item from the drop-down menu.
Once a schema file is associated with a State Sub-Schema operator, the file can be opened by double-clicking the left mouse button on the sub-schema graphic. The file can also be opened by selecting the Open Linked Schema item from the drop-down menu.
Every connected state-transition diagram must define a single state to serve as its Initial State (right click on the desired state and select 'Initial State'). This state will be the active state when the schema first begins executing. When a State Sub-Schema operator is designated as the Initial State its graphic (gray circle) is stamped with a dark green dot. Design Pad G4 will issue an error on processing if no state has been designated as the initial state or if more than one state has been designated as such.
Each transition arc must be associated with a Boolean Variable operator. The transition takes effect when the associated variable's value is HIGH. To associate a transition with a Boolean Variable operator, double-click on the arc to view the Transition Properties dialog shown in Figure 5.11. To make the link, first select the Scope of the Boolean Variable to populate the Variable drop-down combo. If the Scope is set to Local, then the drop-down combo will contain only Boolean Variable operators of Local scope found in the schema containing the transition arc. If the Scope is set to Module, then the drop-down combo will contain all Boolean Variable operators of Module scope found in any schema related to the module that includes the schema that contains the transition arc (including the parent schema linked to the module and any of its descendent sub-schemas). If the Scope is set to Global, then the drop-down combo will contain all Boolean Variable operators of Global scope found in any schema related to the node that includes the schema that contains the transition arc (including the parent schema linked to each module in the node as well as any of their descendent sub-schemas).
Anchor |
---|
| _Ref116710299 |
---|
| _Ref116710299 |
---|
|
Anchor |
---|
| _Toc121289046 |
---|
| _Toc121289046 |
---|
|
Anchor |
---|
| _Toc223175970 |
---|
| _Toc223175970 |
---|
|
Anchor |
---|
| _Toc224024166 |
---|
| _Toc224024166 |
---|
|
Anchor |
---|
| _Toc279736818 |
---|
| _Toc279736818 |
---|
|
Figure 5.11. Transition Properties Dialog
When a state is activated (i.e., when the system transitions into that state) the operators in the underlying sub-schema file can be configured to re-initialize or to continue executing where they left off when the state was last active. This distinction applies only to operators that have memory, meaning that the computation of their output value depends on information from the past. The Addition operator for instance has no memory since its output at time t is simply the sum of its inputs at time t. The Delay Element operator however does have memory since its current output value is equal to a past input value. For example, consider a sub-schema that contains a Delay Element operator that has its Time Delay Multiple property set to 1. If the sub-schema is configured to re-initialize upon activation, then the Delay operator's initial output will be equal to its user-defined initial condition. If the sub-schema is configured to retain its state upon activation, then the Delay operator's initial output will be equal to the input value it sampled just before the state last became inactive.
The activation behavior of a sub-schema is defined in its Sub-Schema Setup dialog---to view the dialog select the Sub-Schema Setup item from the Schema menu. The dialog contains a check-box control in its bottom left quadrant to set the initialization behavior. The other settings in the dialog box do not affect the behavior of the schema when linked to a State Sub-Schema operator.
The concepts described above are best illustrated by example. Consider a hardware interface file consisting of a Chameleon node with one ACP-1 AC Power Module and one DAM-2 Discrete Automation Module linked to the schema shown in Figure 5.12. The schema contains a single state transition diagram with three State Sub-Schema operators, labeled A, B, and C. State A is designated as the initial state as indicated by the dark-green stamp in its graphic. The system can transition from state A to state B, from B to A, from A to C, and from C to B, as indicated by the directed arcs that connect the states. The transition arcs are labeled with the name of a Boolean Variable operator that they are associated with (for instance, the arc from A to B is associated with the Boolean Variable named bABTransition). The transition occurs when the associated Variable operator value is HIGH.
When a State Sub-Schema operator is initially inserted into a schema diagram, it is assigned a generic label by Design Pad G4. To assign a custom label, right-click on the operator and select the Set State Label item from the drop-down menu. (This was done to label the states in the schema of Figure 5.12.)
The schema diagram of Figure 5.12 contains a state transition diagram as well as other operators to execute digital logic (two Digital Input operators feed an AND Gate block which feeds an LED Display operator). At each computation interval, the schema of Figure 5.12 executes these digital logic functions as well as all of the operators contained in the sub-schema file linked to the currently active State Sub-Schema operator.
Each of the states in the Figure 5.12 schema is linked to the sub-schema files shown in Figure 5.13. State A is linked to StateA.scm (Figure 5.13a); state B is linked to StateB.scm (Figure 5.13b); and state C is linked to StateC.scm (Figure 5.13c).
Anchor |
---|
| _Ref116787692 |
---|
| _Ref116787692 |
---|
|
Anchor |
---|
| _Toc121289047 |
---|
| _Toc121289047 |
---|
|
Anchor |
---|
| _Toc223175971 |
---|
| _Toc223175971 |
---|
|
Anchor |
---|
| _Toc224024167 |
---|
| _Toc224024167 |
---|
|
Anchor |
---|
| _Toc279736819 |
---|
| _Toc279736819 |
---|
|
Figure 5.12. Sample hardware interface file and linked top-level schema with state transition diagram.
When the schema of Figure 5.12 first executes (i.e., when the hardware powers up), state A is active. In the underlying sub-schema for state A (Figure 5.13a), a Digital Input operator associated with the DAM-2 module's DI Channel 3 drives two Boolean Variable operators. These variables, named bABTransition and bACTransition are associated with transitions from state A to state B and state A to state C, respectively. When DI Channel 3 in the DAM-2 module is ON, the output of the Digital Input operator is HIGH, thereby setting variables bABTransition HIGH, and bACTransition LOW. With bABTransition HIGH the system transitions from state A to state B. (State A as implemented can be thought of as an IF...THEN statement: if DI Channel 3 is OFF, execute state C, otherwise execute state B.)
The sub-schema associated with state B and shown in Figure 5.13b simply monitors the DAM-2 module's top push-button and initiates a transition back to state A when the button is pressed.
(a)
(b)
(c)
Anchor |
---|
| _Ref116788251 |
---|
| _Ref116788251 |
---|
|
Anchor |
---|
| _Toc121289048 |
---|
| _Toc121289048 |
---|
|
Anchor |
---|
| _Toc223175972 |
---|
| _Toc223175972 |
---|
|
Anchor |
---|
| _Toc224024168 |
---|
| _Toc224024168 |
---|
|
Anchor |
---|
| _Toc279736820 |
---|
| _Toc279736820 |
---|
|
Figure 5.13. State sub-schema documents linked to State Sub-Schema operators in top-level schema of Figure 5.12.
The sub-schema associated with state C and shown in Figure 5.13c itself contains another state-transition diagram that executes a three-step command sequence. The sub-schema files associated with each state (labeled Step 1, Step 2, and Step 3) are shown in Figure 5.14.
(a)
(b)
(c)
Anchor |
---|
| _Ref116788730 |
---|
| _Ref116788730 |
---|
|
Anchor |
---|
| _Toc121289049 |
---|
| _Toc121289049 |
---|
|
Anchor |
---|
| _Toc223175973 |
---|
| _Toc223175973 |
---|
|
Anchor |
---|
| _Toc224024169 |
---|
| _Toc224024169 |
---|
|
Anchor |
---|
| _Toc279736821 |
---|
| _Toc279736821 |
---|
|
Figure 5.14. State sub-schema documents linked to the State Sub-Schema operators in the StateC.scm sub-schema of Figure 5.13c.
Note that the same schema file (StateC12.scm) is associated with states Step 1 and Step 2. The schema activates a relay and monitors a digital input to initiate a transition. When the schema is associated with state Step 1, Figure 5.14a the Relay operator is linked to the DAM-2 module's DO Channel 1 and the Digital Input operator is linked to the DAM-2 module's DI Channel 4. When the same sub-schema document is associated with state Step 2, Figure 5.14b-the Relay operator is linked to the DAM-2 module's DO Channel 2 and the Digital Input operator is linked to the DAM-2 module's DI Channel 5.
The schema file associated with State Step 3 (StateC3.scm) is shown in Figure 5.14c. It de-activates the two relay outputs activated during the earlier steps in the sequence, and sets the Boolean Variable operator named bCBTransition to HIGH. The latter action causes the state-transition diagram in its parent schema (Figure 5.12) to switch from executing state C to executing state B.
The schema file StateC3.scm is configured to re-initialize its operators upon activation. As a result, each time the system enters state C in Figure 5.13c, the entire sequence executes (first state Step 1, then state Step 2, and then state Step 3). If the schema file were not configured to re-initialize upon activation, then the system would immediately resume executing Step 3.