Victor Espinoza – Update 3

This week I designed the Finite State Machine (FSM) that our group is going to be using to control the different states that the Desk-Buddy can be in at any given time.

FSM Design:

Based on our desired project design, I came up with the following State Transition Diagram:

Desk-Buddy State Transition Diagram

We originally had decided on 4 states for the Desk-Buddy (Idle, Happy, Sad, and Mad). In the idle state we were trying to do two things at once (1. look for a face and 2. do nothing after searching for a face for two minutes and not finding it). This is why I choose to break down the original idle state into two states.

The Looking State (State 0) is now in charge of looking for a face. While in the Looking State, the Desk-Buddy can take three different paths:

  1. If a face has not been detected and the Desk-Buddy has been looking for a face for less than 2 minutes, it will stay in the Looking State.
  2. If the Desk-Buddy has detected a face, then it will transition to the Happy State (State 1).
  3. If the Desk-Buddy does not detect a face during the 2 minute time interval, then it will transition into the Idle State (State 4).

The Happy State (State 1) is in charge of displaying the appropriate speaker / LED combinations of happiness to the Desk-Buddy. While in the Happy State, the Desk-Buddy can take two different paths:

  1. If the Desk-Buddy is still detecting a face, then it will stay in the Happy State.
  2. If the Desk-Buddy no longer detects a face, then it will transition into the Mad State (State 2).

The Mad State (State 2) is in charge of displaying the appropriate speaker / LED combinations of anger to the Desk-Buddy. While in the Mad State, the Desk-Buddy can take three different paths:

 

  1. If a face has not been detected and the Desk-Buddy has been in the Mad State for less than 10 seconds, it will stay in the Mad State.
  2. If the Desk-Buddy has detected a face, then it will transition to the Happy State.
  3. If the Desk-Buddy has reached its 10 second time interval in the mad state, then it will transition into the Sad State (State 3).

The Sad State (State 3) is in charge of displaying the appropriate speaker / LED combinations of sadness to the Desk-Buddy. While in theSad State, the Desk-Buddy can take three different paths:

  1. If a face has not been detected and the Desk-Buddy has been in the Sad State for less than 5 seconds, it will stay in the Sad State.
  2. If the Desk-Buddy has detected a face, then it will transition to the Happy State.
  3. If the Desk-Buddy has reached its 5 second time interval in the mad state, then it will transition into the Looking State (State 0).

The Idle State (State 4) is a state that causes the Desk-Buddy to do nothing because nobody is present to interact with it. This state is only entered through the Looking State when the Desk-Buddy has not detected a face for 2 minutes. Our group decided to use a push button (majority rule) to get the Desk-Buddy out of the Idle State and have it start looking for a face again. While in the Idle State, the Desk-Buddy can take two different paths:

  1. If the push button has not been pressed, then the Desk-Buddy will remain in the Idle State.
  2. If the push button is pressed, then the Desk-Buddy will transition to the Looking State.

FSM Implementation:

Our group has decided to program the FSM in C++ (and test it using the Arduino UNO). I created the Finite State Machine for our project, but some of the aspects are not finished yet so I had to improvise on some instances. For example, since our group has not achieved the image processing part of the project yet, I am using a push-and-lock push button to simulate the event when a face is detected by the Desk-Buddy. This push-and-lock button will not be in the final design and will be replaced by the processed image data in the future. Additionally, the speaker outputs have not been generated for the Desk-Buddy yet. Once our group makes more progress, we will be able to combine more of the parts into the state machine and truly test its functionality.

Right now the FSM is only displaying the appropriate LED outputs (since the other aspects of the Desk-Buddy that are included in the FSM are still being developed).

Here is a snippet of what the State Machine looks like (since the whole code is pretty long):

const int LOOKING_STATE = 0;
const int HAPPY_STATE = 1;
const int MAD_STATE = 2;
const int SAD_STATE = 3;
const int IDLE_STATE = 4;
const int INITIALIZE_TIMER = 5;

const int GREEN_LED = 11;  //Green LED signal going to RGB LED Strip
const int RED_LED   = 10;  //Red LED signal going to RGB LED Strip
const int BLUE_LED  = 9;   //Blue LED signal going to RGB LED Strip
const int FACE_DETECTED = 12; //Stimulates a face being detected

void loop() {
  static int current_state = LOOKING_STATE; //Initialize to Looking State
  currentMillis = millis();
  switch(current_state){
    case LOOKING_STATE:
      //PWM Combination for Gray color:
      analogWrite(RED_LED, 20);  // analogWrite values from 0 to 255
      analogWrite(GREEN_LED, 20);  // analogWrite values from 0 to 255
      analogWrite(BLUE_LED, 20);  // analogWrite values from 0 to 255
      if(digitalRead(FACE_DETECTED) == HIGH)
        current_state = HAPPY_STATE;
      else if((unsigned long) currentMillis – previousMillis > 120000 ){
        //Desk-Buddy has been looking for a face for 2 minutes (120000 * .001 = 120s = 2 minutes)
        //and has not found anyone. Go to the idle state…
        current_state = IDLE_STATE;
        previousMillis = currentMillis; //update current time value
      }//end if
      else
        current_state = LOOKING_STATE;
    break;
    case HAPPY_STATE:
      //PWM Combination for Green color:
      analogWrite(RED_LED, 0);  // analogWrite values from 0 to 255
      analogWrite(GREEN_LED, 150);  // analogWrite values from 0 to 255
      analogWrite(BLUE_LED, 0);  // analogWrite values from 0 to 255
      if(digitalRead(FACE_DETECTED) == LOW){
        previousMillis = currentMillis; //update current time value
        current_state = MAD_STATE;
      }//end if
      else
        current_state = HAPPY_STATE;
    break;

*Note: If you want to know more about the code that I wrote ask me about it and I will be more than happy to show you the rest of it.

Here are some pictures of how I set up the hardware in order to communicate with the Arduino UNO:

 

Finally, here is a video that shows the FSM in action:

In the video I display the State Machine going through the various states within it. I also have a stopwatch running on my computer screen so that I could verify that the state machine was staying in each state for the appropriate amount of time. From 0:55 – 2:55 nothing is going on because I am testing the looking state to make sure that it goes into the idle state after it has not detected a face for two minutes.

Advertisements

2 thoughts on “Victor Espinoza – Update 3

  1. Yeah, I have watched some of the movies indicated there. What I didn't watch are "The Dark Knt&qighuot; and "The Incredible Hulk" From what I have heard "The Dark Knight" is so scary most kids got frightened because of the two villians.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s