Skip to content

Specifying system of state machines

Introduction

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

A system of virtual finite state machines can be specified in a StateWORKS project. Starting the new project you will be asked to close the present one.

The tutorial uses the project Pumps from the book to illustrate the design steps. In the book you find detailed requirements and analysis of the control task. For the purpose of this tutorial some 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 project

(a system of finite state machines)

  1. Click on the New button on the toolbar or on the command New in the menu File.
  2. Select the Project icon in the dialog windows.
  3. Select a directory for the project by browsing / editing the edit box Location.
  4. Give the project a name editing the edit box Name. That would be also the actual directory of the project.
  5. Leave this dialog window by clicking on the button OK.

creating_project1

  1. When leaving the dialog window you will be asked whether to close the present project; react appropriately.

You will be confronted with an empty project window. By expanding the groups of objects (Input, etc.) display all RTDB object types available in the project.

creating_project3

The VFSM and Unit groups are empty. Hence, you have to add types to the project needed for the system of state machines.

For the purpose of this tutorial we will add only the VFSM types.

  1. Using command Edit in the menu Project open the dialog window which may be used to add VFSM and UNIT types to the project.

creating_project3

  1. Click on the button Add to open the File Explorer.
  2. Select fsm-files of state machines Device and Pressure.
  3. Confirm by clicking on the button Open.

creating_project4

The VFSM types Device and Pressure have been added to the project.

  1. You may Add or Delete VFSM types at any time while specifying the system.
  2. Leave the dialog window by clicking on the button OK.

creating_project5

The added VFSM types appear in the group VFSM of the RTDB objects.

The VFSM types can be used in the system specification exactly as any other RTDB objects, especially you may define several instances of those types.

A double-click on the VFSM name (for instance Pressure) opens the ST diagram of the state machine Pressure.

creating_project6

Creating a Master state machine

To define a Master state machine create a new state machine, refer to Specifying a state machine.

Store the state machine giving it a name Main and the prefix MAI.

Creating_Master_state_machine

Defining required objects

  1. Open the I/O Object Dictionary.
  2. Select in the field Type: VFSM.
  3. Open the combo box Description which displays a list of VFSM types in the project: device and pressure.

Defining_required_objects1

  1. Add the VFSM of type Device to the I/O Dictionary; give it a name Device.
  2. Add two VFSMs of type Pressure to the I/O Dictionary; give them names Pressure1 and Pressure2.

Defining_required_objects2

  1. Similarly, add the CMD-OUT of type Device to the I/O Dictionary; give it a name DeviceCmd.
  2. Similarly, add two CMD-OUT of type Pressure to the I/O Dictionary; give them names Pressure1Cmd and Pressure2Cmd.

Note that the Master state machine has already been given the default object MyCmd of a type CMD-IN.

Defining_required_objects3

Defining Master Input Names

  1. Open the Input Name Dictionary
  2. Select an I/O Object ID of type Pressure.
  3. Open the list of object Input Values, which displays all the states of a state machine Pressure.

Defining_Master_Input_Names1

  1. Select a value (effectively a state) in the field Input Value, for instance Idle.
  2. A click on the button Add creates a default Input Name; you may edit it or accept as it is.
  3. A next click on the button Add adds the name to the Input Name Dictionary.

Defining_Master_Input_Names2

  1. Leave the dialog window with OK.

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

If you define all required Input Names the Input Name Dictionary may look for instance as below.

Note: Open “Input Name Dictionary” in Main.fsm from the VFSM folder.

Defining_Master_Input_Names3

Defining Master Output Names

  1. Open the Output Name Dictionary
  2. Select an I/O Object ID of type Pressure1Cmd.
  3. Open the list of object Output Values which displays the commands of a state machine Pressure.

Defining_Master_Output_Names1

  1. Select a value (effectively a command) in the field Output Value, for instance Cmd_Start.
  2. Clicking on the button Add suggests a default Output Name; you may edit it or accept as it is.
  3. A next click on the button Add adds the name to the Output Name Dictionary.

Defining_Master_Output_Names2

  1. Leave the dialog window with OK.

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

If you define all required Output Names the Output Name Dictionary may look for instance as below.

Note: Open “Output Name Dictionary” in Main.fsm from the VFSM folder.

Defining_Master_Output_Names3

Defining Master State Names

Create states which you need for a specification of the state machine Main.

Note: Open Main.fsm from the VFSM folder.

Defining_Master_State_Names

Specifying Master state machine

The specification of a Master state machine is done exactly as any other state machine. The ST diagram of the state machine Main is shown below.

Note: Open Main.fsm from the VFSM folder.

Specifying_Master_state_machine1

To complete the task add the Main state machine type to the project (Project → Edit).

Specifying_Master_state_machine2

SMS diagram

You have now created the system of state machines as shown in this SMS diagram.

But to finish the process, and generate this diagram, you need now to do some further work to configure your Project. This process will be explained in the tutorial Specifying RTDB (execution environment).

SMS_diagram

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
[5] StateWORKS: Specifying a state machine


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