FSM Lecture 15: Exercise-003 Drawing state transitions

  • Post author:
  • Post category:Blog

 

Exercise-003 Drawing state transitions

 

 

In the previous article, we wrote some Entry and Exit actions for various states.

Transitions:

The number of Transitions we draw per state depends on the number of events the state respects or processes. 

Drawing state transitions
Figure 1. Various Events

 

I have already shown this table(Figure 1) to you. 

We have got 5 Events; at maximum there could be 5 Transitions from each state because there are five events. 

 

First, let’s start with the IDLE state, and you have to check whether that state processes a particular event or not. If it doesn’t process or if it doesn’t respect that event, then you can ignore it. You need not define it. 

INC_TIME: Let’s start with Increment Time (INC_TIME) in the case of IDLE state. The application is in an IDLE state, whenever the increment time event is received, it should go to the TIME_SET state because the user wants to set the time. That’s why the user has pressed the ‘+’ or ‘-’ button.

Drawing state transitions
Figure 2. Transition

 

We will take one Transition.

Go to the panel, select the Transition, and draw from wherever you want; figure 2 shows the Transition. 

And the trigger is the event name. i.e., INC_TIME. Currently, I don’t give any Guard for this. Whenever the ‘+’ button is pressed, it should take a transition. 

The Action is the user has pressed the ‘+’ button, we have to increment the time details. That’s why Action could be mobj->c_time += 60; current time has to be increased. 60 seconds I have to add to the current time variable. Because the minutes should increase whenever the ‘+’ button is pressed, that’s why I’m adding 60 to that variable. That’s the associated Action.  

DEC_TIME: Now let’s process the next event, decrement time (DEC_TIME). When the c_time=0, the decrement time has no meaning. The user cannot press the negative button when the time is 0 because we don’t use negative time in this application. That’s why IDLE state ignores, doesn’t respect the decrement time event. You forget it.  

ABORT: The next event is ABORT. There is nothing to Abort because the operation has not at started. When do you use Abort? When something has started. Nothing has started in the IDLE state. That’s why it doesn’t respect the ABORT event also. 

START and PAUSE:  There is nothing to PAUSE, and the START doesn’t happen from here. To START something, the time has to be set first. That’s why START can only happen in other states, not in the IDLE state. That’s why the IDLE state doesn’t respect the START and PAUSE event. Just look at IDLE state only, don’t worry about other states. I’m just talking with respect to IDLE state only. 

TIME_TICK Event: We have one project requirement. The requirement says the application must beep 20 times when it returns to the IDLE mode.

For every 500 milliseconds, the application has to beep. Beep for 10 milliseconds. A short beep. It has to do 20 times, and then it should go to the silent mode, I mean no more beeping. These things can be easily implemented in an Arduino framework.

We will implement this as an Internal Transition in the IDLE state.

Drawing state transitions
Figure 3.TIME_TICK Event for IDLE state

 

Select the IDLE mode, and go to the Internal, Trigger(set the trigger); you click on Add, the trigger is ‘TIME_TICK.’ That’s a trigger. And this event has a parameter. The parameter you write inside the parenthesis. ‘SS,’ that’s a trigger. 

Guard is e->SS==5 (for every 500 milliseconds).If SS==5 means 500 milliseconds, ‘e’ means event received. That’s a TIME_TICK and its parameter SS(sub-second).

Action is do_beep(); a helper function. That’s an Internal Transition.

 

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.