Skip to content

Specifying state machine

Introduction

The tutorial teaches you how to prepare the specification of a virtual finite state machine using StateWORKS Studio. We assume that you know about the VFSM concept.

When it starts StateWORKS Studio opens the last project or nothing if started the first time. A specification of a new state machine is independent of the project opened: you may leave it or close it.

The specification uses RTDB (real time data base) objects, such as digital input (DI), digital output (DO), timer (TI), etc.

The VFSM and UNIT object type are “empty” and we may use them to specify specific variants of those types.

The tutorial uses the project Pumps to illustrate the design steps from the book where you find detailed requirements and the analysis of the control task. For the purpose of that tutorial a partial specifications are provided which may be loaded to accelerate the training (observe corresponding notes).

Terminology table

TerminologyExplanation
Always (table)A table used for specification of combinational systems or Input actions valid for all states
Entry actionAn Output name describing an action performed by entering a state
Exit action (written also as eXit action)An Output name describing an action performed by exiting a state
Id nameA name of an object
I/O Object DictionaryA list of all defined objects
I/O Object Idsee: Id name
Init (flag)A flag: if marked instructs the execution system (RTDB) to initialize the virtual input to that value
Init (state)A default state which cannot be deleted but can be renamed
Inputsee: Input Name
Input (tab)see: Input Name Dictionary
Input actionAn Output name describing action performed if an Input action condition is due
Input action conditionA condition defined using Input names linked by AND and OR operators
Input action expressionInput action condition and Input action
Input action priorityThe sequence of Input action expressions in the ST table; used for documentation purpose
Input NameA name of a control condition (defined on an Input Value)
Input Name DictionaryA list of all defined Input Names
Input ValueObject input value
MyCmdA default Input Name of a type CMD which cannot be deleted but can be renamed
Next State priorityThe sequence of state transitions in the ST table; determines the execution sequence
Operators: AND (&), OR (|)Boolean operators
Outputsee: Output Name
Output (tab)see: Output Name Dictionary
Output NameA name describing an action (defined on an Output Value)
Output Name DictionaryA list of all defined Output Names
Output ValueAn Object output value
PrefixA VFSM specific prefix used in h-files generated for each VFSM
ST diagramA state transition diagram used for graphic presentation of a state machine behavior
ST tableA state transition table used for detailed specification of a state.
Statesee: State Name (drawn as a circle on the ST diagram)
State NameA state name
State Name DictionaryA list of all defined State Names
TransitionA transition between two states (drawn as an arrow on the ST diagram)
Transition conditionA condition defined using Input names linked by AND and OR operators
Transition expressionNext state and Transition condition

Creating a virtual finite state machine (VFSM)

A virtual finite state machine (VFSM) is an RTDB object type.

Creating a new VFSM means a definition of a new specific VFSM type.

The new VFSM object type gets a name, for instance Pressure and can be used in the project exactly as any other RTDB objects: once or in several instances.

  1. Click on the New button on the toolbar or on the command New in the menu File.
  2. Select the VFSM File icon in the dialog window.
  3. Leave this dialog window by clicking on the OK button.

Creating_VFSM1

  1. Select the radio button Generic.
  2. Leave the dialog window by clicking on the OK button.

Creating_VFSM2

A state transition (ST) diagram will be created, with a state Init and the table Always.

The state machine is given a default name VFSM1; that name can be changed while saving the file.

Creating_VFSM3

Defining required objects

  1. Open the I/O Object Dictionary by clicking on the icon on the toolbar or on the command I/O Object in the menu Dictionary or using the function key F.
  2. The dialog window opens with a default object MyCmd of type CMD-IN. That object cannot be deleted.

Defining_required_objects1

  1. Select a Type of object, for instance TI (timer).

Defining_required_objects2

  1. Define a name by clicking on the button Add the name TI0 appears in the Id name field. If you do not like the name edit it in the Id name field.

Defining_required_objects2

  1. Add the name to the I/O Object Dictionary by clicking on the button Add.

Defining_required_objects3

If you add all required objects the I/O Object Dictionary may look for instance as below (Project Pumps: Open I/O Object Dictionary from Pressure.fsm).

The list may be changed at any time: the objects may be Deleted, Added and Modified.

Defining_required_objects4

  1. Leave the dialog window with OK.

Defining Input Names

  1. Open the Input Name Dictionary by clicking on the icon on the toolbar or on the command Input… in the menu Dictionary or using the function key F.

Defining_Input_Names1

  1. Select the I/O Object ID, for instance MyCmd.
  2. Select a command value in the Input Value field, for instance 1.
  3. Edit the Input Name, calling the value, for instance Cmd_Start.

Note that there is no automatic suggestion of a name for objects whose values are numbers.

Defining_Input_Names2

  1. Add the name Cmd_Start to the Input Name Dictionary by clicking on the button Add.

Defining_Input_Names3

  1. Select another I/O Object ID, for instance TI0.
  2. Open the list of object Input Values.
  3. Select the required value, for instance OVER.

Defining_Input_Names4

  1. Define a name by clicking on the button Add: the name TI0_OVER appears in the Input Name field. If you do not like the name edit it in the Input Name field.

Defining_Input_Names5

  1. Add the name TI0_OVER to the Input Name Dictionary by a new click on the Add button.

Defining_Input_Names6

If you define all required Input Names the Input Name Dictionary may look for instance as below (Project Pumps: Open Input Name Dictionary from Pressure.fsm).

The Dictionary may be changed at any time: selected names may be Deleted, Added and Modified.

Defining_Input_Names7

  1. Leave the dialog window with OK.

Defining Output Names

  1. Open the Output Name Dictionary by clicking on the icon on the toolbar or on the command Output… in the menu Dictionary or using the function key F3.

Defining_Output_Names1

  1. Select an I/O Object ID, for instance Ti.
  2. Open the list of object Output Values.
  3. Select required value, for instance ResetStart.

Defining_Output_Names2

  1. Define a name by clicking on the button Add the name TI0_ResetStart appears in the Output Name field. If you do not like the name edit it in the Output Name field.

Defining_Output_Names3

  1. Add the name Ti_ResetStart to the Output Name Dictionary by a new click on the button Add.

Defining_Output_Names4

If you define all required Output Names the Output Name Dictionary may look for instance as below (Project Pumps: Open Output Name Dictionary from Pressure.fsm).

The Dictionary may be changed at any time: selected names may be Deleted, Added and Modified.

Defining_Output_Names5

  1. Leave the dialog window with OK.

Defining State Names

  1. Open the State Name Dictionary by double-clicking on the ST diagram.

The dialog window opens with a default state Init. That state cannot be Deleted but can be renamed: select it, edit and Modify.

Defining_State_Names1

  1. Edit a new state name for instance Idle.
  2. Add the state name to the State Name Dictionary by clicking on the button Append.

Defining_State_Names2

The state names can be Modified and Deleted.
The sequence of names in the list may be changed using Buttons Move Up and Move Down. The sequence has only cosmetic relevance, for instance for documentation purpose.

  1. Leave the dialog window by clicking on the button OK.

The state Idle will appear on the ST diagram and the ST table of the state Idle opens.

Defining_State_Names3

  1. Repeating that procedure, you may create a few states as shown below.

Defining_State_Names4

Specifying Transitions

  1. Position the cursor over a state (for instance Starting).
  2. Pushing the right mouse button, draw a transition arrow to another state (Idle), the ST table opens.

Specifying_Transitions1

The content of Input, Output, and State dictionaries is available as overlapped tabs; the position of the cursor in the ST table activates the relevant Dictionary.

As the cursor is in the transition condition field the Input Names Dictionaries will be active.

Specifying_Transitions2

  1. A click on the required name (Ti_OVER) in the Input tab copies the name into the field selected by the cursor (the transition field).

Specifying_Transitions3

AND and OR operators as well as brackets available at the top of the Input tab may be copied into the transition field.

May look for instance as below (Project Pumps: Open ST Table Starting from Pressure.fsm).
e.g. clicking first on the OR operator ( | ) and later on the name Ofun_OwnerError it is possible to define a more complex transition.

Specifying_Transitions4

Storing VFSM file

You may store the VFSM file at any time by clicking on toolbar icon or on the Save command in the menu File or using the shortcut CTRL/S.

During saving you define the file name and you are asked to define a VFSM Prefix. The 3-characters Prefix will be used in a h-file generated by performing the command Project → Build. You may accept the default Prefix which is built of the three first letters of the file name.

Let’s name the file Pressure and define the Prefix REG. The Prefix may be changed at any time using the command Options → Prefix.

Storing_VFSM_file

Specifying Transitions

Similarly you may specify transition conditions to other states receiving eventually the ST table of the state Starting shown below.

The sequence of Next states in the ST table defines their execution priority. You may change the priority using toolbar arrows or commands Move expression in the menu Edit.

Specifying_Transitions5

The ST diagram of the VFSM Pressure will look at that moment as shown below.

Specifying_Transitions6

Specifying Entry and Exit Actions

  1. Position the cursor in the field Entry action: the tab Output will be active.
  2. Select a name in the tab Output (Timer_ResetStart) and by clicking on the name copy it to the Entry action field.

Specifying_Entry_and_Exit_Actions

Specifying Actions

Repeating that procedure for fields Entry action and eXit action you get the ST table shown below.

Specifying_Actions1

Specification of Input actions requires:

  • Definition of input action condition: position the cursor in the field Input action condition.
  • Select the name (Timer_OVER) in the tab Input and clicking on it copy it to the field Input action condition.

Specifying_Actions2

and:

  • Definition of action: position the cursor in the field Output action.
  • Select the name (Al_PressureError) in the tab Output and by clicking on it copy it to the field Output action.

Specifying_Actions3

Using toolbar tabs or command Insert, Append, Delete expression in menu Edit you may specify any number of Input action expressions.

The sequence of Input action expressions may be changed using toolbar arrows or commands in menu Edit.

The sequence of Input action expressions does not play any role and it does not define any execution priority. Changing of the sequence is provided for the user’s convenience, to make his documentation easier to follow.

Specifying ST table

Eventually the ST table may be complete as shown below.

Specifying_ST_table1

To make it easier to understand you should add a description in the field Comment.

Specifying_ST_table2

Specifying the table Always

You may specify Input actions valid for all states.

  1. Clicking on the table Always in the ST diagram open the table as below.
  2. You may define, edit and manipulate the content of fields: Input action condition and Input action in a very similar way as in the ST table.
  3. You may add a description in the Comment field.

Specifying_the_table_Always1

Eventually you get the content of the table Always as shown below.

Specifying_the_table_Always2

The VFSM specification is ready

If you have specified ST tables for all states and the table Always the task is done: the virtual finite state machine is specified and its ST diagram is shown below (Project Pumps: Pressure.fsm).

VFSM_specification_ready.png

References

[1] Book Modeling Software with Finite State Machines: A Practical Approach
[2] StateWORKS Studio Help
[3] StateWORKS Development Tools: User’s Guide & Training Manual
[4] StateWORKS: Technical Notes


Here you can view the unedited file directly from the author: PDF