FSM Lecture 13: Exercise-003 States and Initial Psuedostates

  • Post author:
  • Post category:Blog

 

Exercise-003 States and Initial Psuedostates

 

 

The Productivity Timer application is our second exercise. So for we have understood the project requirements in the previous article.

Map different situations of your project into states

  1. IDLE
  2. TIME SET 
  3. PAUSE
  4. COUNTDOWN
  5. STAT

These are the different situations and we are converting these situations into states.

 

Now let’s look at the various events we will use for this application.

Figure 1. Various Events
Figure 1. Various Events
  • Press ‘+’ Button:   When the user uses the ‘+’ button, the event generated is INC_TIME, which is an event name or the signal name. And it has got no associated parameters.
  • Press ‘-’ Button: When the user presses the ‘-’ button, one event would be generated and its signal name is DEC_TIME, and it has no associated parameters.  
  • Press ‘START’ or ‘PAUSE’ Button: Whenever a user presses the START or PAUSE button, the signal generated is START_PAUSE.
  • Press ‘+’ and ‘-’ button together: User can press ‘+’ and ‘-’ button simultaneously, which is ABORT.
  • TIME_TICK Event: This is not a user-generated event; this is system-generated. And it has got one associated parameter ‘SS’ (stands for sub-second). This event is system generated for every 100 milliseconds.  The ‘SS’ parameter value will be between 1 to 10. 1 means 100 milliseconds; 10 means 1000 milliseconds, which means 1 second. Only the TIME_TICK event has got one associated parameter, which is SS.

 

Extended state variables

Extended state variables are nothing but those variables which appear throughout the state machine diagrams.

These variables will help us to capture various data and it will help us take decisions on the state machine diagram, help us draw state machines in such a way that we can reduce the number of states used, and we can implement various decision-making on the state machine, etc.

States and Initial Psuedostates
Figure 2. Extended state variables

I’m going to take three variables for this application.

  • curr_time:  The current time variable holds the time that the user has selected. You know that the user can select the time using the ‘+’ or ‘-’ button; that’s a user set time, a current time.
  • elapsed_time:  This variable holds the number of seconds that’s been elapsed.
  • Pro_time:  This variable holds the productive time spent by the user. pro_time is used to show the statistics. 

You can use more variables if you want, but currently, I stick with these three variables, which we keep under the main application structure. That is shown in Figure 2.

 

Pseudo states

  • Initial
  • Choice
  • Join
  • Deep history
  • Shallow history

Refer [OMG® UML 2.5.1] for complete list of pseudo states.

 

Initial: 

The initial Pseudostate represents a starting point for a Region; that is, it is the point from which the execution of its contained behavior commences when the Region is entered via default activation.

It is the source for at most one Transition, which may have an associated effect behavior, but not an associated trigger or Guard. That can be at most one Initial Vertex in a Region.

States and Initial Psuedostates
Figure 3. Initial Pseudostate

Figure 3 shows the Initial Pseudostate.  It is a black dot symbol, a circle filled with black color.

An initial Pseudo state can have at most one outgoing transition. You use an arrow and pull towards the state, which has to be the initial state of your state machine diagram.

And for our application, the IDLE state is the Initial State. 

In the diagram, the IDLE state is the initial state. Now let’s begin drawing the external transitions, internal transitions, internal activities right from the IDLE state (figure 3).

And the Initial Transition cannot have trigger, cannot have guard,  you can only mention the action.

 

States and Initial Psuedostates
Figure 4. Initial Action

What could be our Initial Action?

We may have to initialize our extended state variables. I will call the main object mobj. mobj is the main object or pointer to the main object. 

And we are writing the state machine for this object. So, the action for the Initial Transition could be let’s initialize the extended state variables value to 0. I would just make curr_time = 0; and mobj-> elapsed_time = 0; and mobj->pro_time=0; these are the actions associated with the Initial Transitions. mobj is an object, and curr_time, elapsed_time, pro_time are the object’s attributes. I initialize them to 0(Figure 4).

 

FastBit Embedded Brain Academy Courses

click here: https://fastbitlab.com/course1 

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.