StatemachineExtension
class StatemachineExtension
The statemachine of a controller that extends another controller. It holds only what this controller changes in the inherited statemachine: StateExtensions and StateOverrides of inherited states, JunctionExtensions of inherited junctions, additional states and junctions, and optionally a StartOverwrite. For code generation, UP merges the inherited statemachine and the changes of all controllers in the inheritance chain into one complete statemachine of this controller.
What a statemachine extension is for
A controller that extends another controller inherits its statemachine. The StatemachineExtension of the derived controller holds only the changes, not a copy of the inherited statemachine. When generating, UP builds one complete statemachine per controller from the inherited statemachine and the changes of all controllers in the inheritance chain, the same way for B&R, Beckhoff and S7-TIA.
In practice, a shared base controller holds the common behaviour of a device type, and a project controller extends it for one machine.
Extend or override
| What you want | Element | What stays inherited |
|---|---|---|
| Additional code in an inherited state: before, after or between the inherited functions, or instead of one of them | StateExtension, function with a position | All other functions, the transitions and the sub-states |
| An additional transition out of an inherited state, or one inherited transition replaced | StateExtension, transition with a position | All other transitions. The transitions of a state are checked in list order; the first one whose condition is true is taken |
| More sub-states or junctions, or another first sub-state, in an inherited super state | StateExtension: states, junctions, StartOverwrite (only for states with sub-states) | The inherited sub-states, functions and transitions |
| Another inside for an inherited state | StateOverride | The state, its place and its inherited transitions |
| An additional or a replaced transition of an inherited junction | JunctionExtension (junctions cannot be overridden) | All other transitions of the junction |
| New states on the top level | States of the StatemachineExtension | The complete inherited statemachine |
Practice, not checked by UP:
- Extend first. Override only when the inside of the inherited state no longer fits: an override uses only the inherited functions it calls through superCall and none of the inherited sub-states, so later changes to the other functions and to the sub-states in the base controller have no effect in this controller. The override keeps the inherited transitions; later changes to them in the base controller still apply, except for a transition the override replaces with a TransitionOverwrite.
- Give each inherited state at most one StateExtension or StateOverride per controller. With several, the generator takes the functions and transitions from only one of them, but looks for sub-states and a StartOverwrite in all StateExtensions of that controller.
What a StateOverride keeps and replaces
- Kept: the state itself, its place in the statemachine and the transitions it inherits. Each of these transitions can be replaced by its own TransitionOverwrite, and more transitions can be added. They are checked in every cycle, also while a sub-state of the override is active.
- Replaced: the inherited entry, state, exit and simulation functions. The override has its own functions; each of them can call selected inherited functions first (superCall).
- Replaced: the inherited sub-states. The override can have its own states with its own start, also for a state that had no sub-states before.
Several levels of inheritance
If a controller extends a controller that itself extends another one, UP collects the StateExtensions and StateOverrides of one state from this controller towards its base, up to the nearest StateOverride. Without a StateOverride, the StateExtensions of all controllers apply, from the base towards this controller. With one:
- The nearest StateOverride starts from the state as UP merges it for the controller it extends, that is with the changes of all controllers closer to the base. It keeps these merged transitions, including transitions that StateExtensions closer to the base added or replaced, and each of them can be replaced by its own TransitionOverwrite. Its functions can call the merged inherited functions through superCall, also functions that StateExtensions closer to the base added.
- The other functions, the sub-states and the StartOverwrite of the StateExtensions closer to the base are not used.
- The StateExtensions of the controllers between the override and this controller then add their functions, transitions, sub-states and StartOverwrite on top, from the override towards this controller.
Example: a lifting table variant
A shared base controller for a lifting table has the commands UP and DOWN with the super states UP_Group
(UP_busy -> UP) and DOWN_Group (DOWN_busy -> DOWN). A variant for one machine extends this
controller:
UP_busygets a StateExtension with an entry function at position before, which releases a brake. It runs before the inherited entry functions.- The same StateExtension adds a transition at position before to an inherited stop state, taken when an upper limit switch is active. It is checked before the inherited transitions.
DOWN_busygets a StateOverride with the sub-statesDOWN_FASTandDOWN_SLOW(startDOWN_FAST) instead of the inherited single step. Its inherited transition toDOWNstays and ends the movement as before.
Additional states and junctions
Additional flat states and junctions can be implemented.
State diagram
In StatemachineExtensions it is possible to create a merged diagram. All inherited elements are grayed out.
Create a diagram in a statemachine extension
To avoid having to draw the diagram of a stateExtension completely from scratch, the diagram of the basic controller can be copied.




