Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Capture each system as a State Machine (as described in chapter 3). Use RIBS and

ID: 3843024 • Letter: C

Question

Capture each system as a State Machine (as described in chapter 3). Use RIBS and RIMS as appropriate below. (Be sure RIBS' ‘type’ option has ‘Asynchronous SM’ selected). Be sure to use C language for RIMS and use the #include "rims.h" LIBRARY!

2. An automatic door at a store has a sensor in front (A1) and behind (A0). The door opens (B0=1) when a person approaches from the front, and stays open as long as a person is detected in front or behind. If the door is closed and a person approaches from the behind, the door does not open. If the door is closed and a person approaches from the front but a person is also detected behind, the door does not open, to prevent hitting the person that is behind.

Explanation / Answer

#include<rims.h>

enum {
   IDLE_1 = 0,
   STATE_1_A,
   STATE_1_B
};

// state values for state2

enum {
   IDLE_2 = 0,
   STATE_2_A,
   STATE_2_B
};

uint8_t state1;

uint8_t state2;
bit flag1, flag2, flag3, flag4;

void checkBitFlags(void);
void checkState1(void;
void checkState2(void);

void main(void)
{
   state1 = IDLE_1;
   state2 = IDLE_2;

   for(;;)
   {
       checkBitFlags();
       checkState1();
       checkState2();
   }
}


void checkState1(void)
{
   switch(state1)
   {
   case IDLE_1:
       if(flag1 == TRUE)
       {
            state1 = STATE_1_A;
       }
       break;

   case STATE_1_A:
       if(flag2 == TRUE)
       {
            state1 = STATE_1_B;
       }
       break;

   case STATE_1_B:
       if(flag1 == FALSE)
       {
            state1 = IDLE_1;
            break;
       }
       if(flag2 == FALSE)
       {
            state1 = STATE_1_A;
       }
       break;

   default:
       //TODO invalid state - reset, perhaps?
       break;
   }
}

void checkState2(void)
{
   switch(state2)
  

{
case IDLE_2:
if(flag3 == TRUE)
{
state2 = STATE_2_A;
}
break;

case STATE_2_A:
if(flag4 == TRUE)
{
state2 = STATE_2_B;
}
break;

case STATE_2_B:
if(flag3 == FALSE)
{
state2 = IDLE_2;
break;
}
if(flag4 == FALSE)
{
state2 = STATE_2_A;
}
break;

default:
//TODO invalid state - reset, perhaps?
break;
}

}

2.)

#include<stdio.h>

void main()
{
while (1) {
if(!A0 && !A1)
{
!B0;
}
if(A0 && !A1)
{
B0 = 1;
}
if (A1)
{
B0 = 0;
}
/*if (A1 && A0)
{
!B0;
}*/
}
}