.Modelica_StateGraph2.UsersGuide.Tutorial.StepsAndTransitions

Information

The basic elements of a StateGraph2 model are Steps and Transitions. An example is shown in the next Figure:

The Figure above is a screen-shot of the diagram animation of the StateGraph2 model: Whenever a Step is active or a Transition can fire, the corresponding component is marked in green color.

Steps represent the possible states a StateGraph2 can have. If a Step is active the Boolean variable active of the Step is true. If it is deactivated, active = false. At the initial time, all "usual" Steps are deactivated. The inital Step objects are Steps that are activated at the initial time. They are characterized by a small arrow pointing to the Step (see Figure above) and are defined by setting parameter "initialStep = true" in a Step, see next Figure.

Transitions are used to change the state of a StateGraph2. When the Step connected to the input of a Transition is active and the Transition condition becomes true, then the Transition fires. This means that the Step connected to the input to the Transition is deactivated and the Step connected to the output of the Transition is activated.

The Transition condition is defined via the parameter menu of the Transition object. Clicking on object "T1" in the above Figure, results in the following menu:

In the input field "condition", any type of time varying Boolean expression can be given (in Modelica notation, this is a modification of the time varying variable condition). Whenever this condition is true, the Transition can fire. Additionally, it is possible to activate a timer, via delayedTransition (see menu above) and provide a waitTime. In this case the firing of the Transition is delayed according to the provided waitTime, provided that the condition remains true and the preceding Step remains active during the entire waitTime. The Transition condition and the waitTime are displayed in the Transition icon.

In the above example, the simulation starts at initialStep. After 2 seconds, Transition T1 fires and Step2 becomes active. After another second Transition T2 fires and Step3 becomes active. After an additional second Transition T3 fires and intialStep becomes active. Since time >2, T1 fires at once and Step2 becomes active again, and so on.

In JGrafcharts, Grafcet and Sequential Function Charts, the network of Steps and Transitions is drawn from top to bottom. In StateGraph2 models, no particular direction is defined, since Steps and Transitions are models with input and output connectors that can be arbitrarily placed and connected. Since users of Grafcet and SFC are used to the "top to bottom drawing", in all examples of this library, this convention is used. This has the additional advantage that block diagrams to program actions can be conveniently drawn from left to right as it is usual for block diagrams.

When parameter use_conditionPort is enabled at a Step, the firing condition can be provided as Boolean input signal, instead as entry in the menu of the Transition. An example is given in the next Figure:

In the Figure, additionally parameter use_activePort is set to true at Step2 to provide the active flag of this Step as Boolean output signal. To this output, component OnDelay is connected. If the input of this block becomes true, the output becomes true after a delay time. If the input of this block becomes false, the output is immediately reset to false as well. The output signal of the onDelay block is used as condition input of the Transition. As a result, "T2" fires, once Step "Step2" has been active for 1 second. Of course, any other Modelica block with a Boolean output signal can be connected to the condition input of such a Transition block as well. More details how define such actions graphically are given in section "Actions"

Subgraphs can be aggregated into superstates by using the Parallel component. This component acts both as a composite step (having just one branch) and as a Step that has parallel branches that are executed in parallel to each other. For details, see "section Parallel".

The execution model of a StateGraph2 graph follows from its Modelica implementation: Given the states of all Steps, i.e., whether a Step is active or not active, the equations of all Steps, Transitions, Transition conditions, actions etc. are sorted resulting in an execution sequence to compute essentially the new values of the Steps. If conflicts occur, e.g., if there are more equations as variables, of if there are algebraic loops between Boolean variables, an error occurs. Once all equations have been processed, the active variables of all Steps are updated to the newly calculated values. Afterwards, the equations are again evaluated. The iteration stops, once no Step changes its state anymore, i.e., once no Transition fires anymore. Then, simulation continuous until a new event is triggered, (when a relation changes its value).

With the Modelica_EmbeddedSystems library a StateGraph2 model can also be executed within a discrete controller that is called periodically. Furthermore, production code can be downloaded to a target processor.


Generated at 2024-12-17T19:26:02Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos