GitLab system status is available here and here

Commit a94dcb31 authored by Singaravelavan Rajesh's avatar Singaravelavan Rajesh
Browse files

LAB PART 8 CHecked off:

parent 0f7402ac
......@@ -39,8 +39,8 @@
* MODULE #DEFINES *
******************************************************************************/
#define BATTERY_DISCONNECT_THRESHOLD 175
#define DARK_THRESHOLD 600
#define LIGHT_THRESHOLD 400
#define DARK_THRESHOLD 700
#define LIGHT_THRESHOLD 500
/*******************************************************************************
* EVENTCHECKER_TEST SPECIFIC CODE *
******************************************************************************/
......
This diff is collapsed.
......@@ -45,8 +45,9 @@
#define FWD_TIMEOUT 1000
#define TR_TIMEOUT 250
#define RIGHT_TIMEOUT 510
#define TR_TIMEOUT 500
#define RIGHT_TIMEOUT 300
/*******************************************************************************
* PRIVATE FUNCTION PROTOTYPES *
******************************************************************************/
......@@ -166,89 +167,37 @@ ES_Event RunTemplateFSM(ES_Event ThisEvent) {
case FORWARD: // in the first state, replace this with appropriate state
// goes forward at 75%
Roach_RightMtrSpeed(-75);
Roach_LeftMtrSpeed(-75);
// If not stuck
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
stuck = 0;
}
// Goes to backward state
if (ThisEvent.EventType == FRONT && stuck) {
nextState = BACKWARD;
makeTransition = TRUE;
Roach_RightMtrSpeed(-100);
Roach_LeftMtrSpeed(-57);
}
// Goes back a little bit to turn right
if (ThisEvent.EventType == FRONT && !stuck) {
if (ThisEvent.EventType == FRONT || ThisEvent.EventType == FR || ThisEvent.EventType == FL) {
ES_Timer_InitTimer(1, TR_TIMEOUT);
nextState = TRBACK;
makeTransition = TRUE;
}
// if we reach the dark
if (ThisEvent.EventType == DARK) {
ES_Timer_InitTimer(1, 1000);
}
if(ThisEvent.EventType == DARK){
ES_Timer_InitTimer(1, 500);
nextState = STOP;
makeTransition = TRUE;
}
break;
case BACKWARD:
// goes backward
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(75);
// goes forward a little bit to turn right
if (ThisEvent.EventType == BACK) {
ES_Timer_InitTimer(1, TR_TIMEOUT);
nextState = TRFWD;
makeTransition = TRUE;
}
break;
case TRBACK:
// goes back a little bit
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(75);
// goes to turn right state
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
ES_Timer_InitTimer(1, RIGHT_TIMEOUT);
nextState = TR;
makeTransition = TRUE;
}
break;
case TRFWD:
// goes forward a little bit
Roach_RightMtrSpeed(-75);
Roach_LeftMtrSpeed(-75);
// goes to turn right state
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
ES_Timer_InitTimer(1, RIGHT_TIMEOUT);
nextState = TR;
makeTransition = TRUE;
}
break;
case TR:
// turn right
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(-75);
// goes to forward state after turning right
case TRBACK:
Roach_RightMtrSpeed(100);
Roach_LeftMtrSpeed(0);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
stuck = 1;
ES_Timer_InitTimer(1, FWD_TIMEOUT);
nextState = FORWARD;
makeTransition = TRUE;
}
break;
case STOP:
// Edge case to make sure we arent stuck and are fully in the dark
Roach_RightMtrSpeed(-100);
Roach_LeftMtrSpeed(-100);
Roach_RightMtrSpeed(-75);
Roach_LeftMtrSpeed(-75);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
nextState = FINISH;
......@@ -260,6 +209,11 @@ ES_Event RunTemplateFSM(ES_Event ThisEvent) {
Roach_RightMtrSpeed(0);
Roach_LeftMtrSpeed(0);
Roach_LEDSSet(0xFFF);
if(ThisEvent.EventType == LIGHT ){
nextState = FORWARD;
makeTransition = TRUE;
}
default: // all unhandled states fall into here
break;
} // end switch on Current State
......
......@@ -4,8 +4,8 @@
<memory name="program">
<units>bytes</units>
<length>126464</length>
<used>33796</used>
<free>92668</free>
<used>33436</used>
<free>93028</free>
</memory>
<memory name="data">
<units>bytes</units>
......
......@@ -2,6 +2,8 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/TemplateEventChecker.c</file>
</group>
</open-files>
</project-private>
......@@ -41,6 +41,7 @@ typedef enum {
InitPSubState,
STOP,
MOVE_AWAY,
MOVE_AWAY2,
FINISH,
} TemplateSubHSMState_t;
......@@ -48,6 +49,7 @@ static const char *StateNames[] = {
"InitPSubState",
"STOP",
"MOVE_AWAY",
"MOVE_AWAY2",
"FINISH",
};
......@@ -110,6 +112,7 @@ uint8_t InitBatterySubHSM(void) {
* @author J. Edward Carryer, 2011.10.23 19:25
* @author Gabriel H Elkaim, 2011.10.23 19:25 */
unsigned int hit = 0;
ES_Event RunBatterySubHSM(ES_Event ThisEvent) {
uint8_t makeTransition = FALSE; // use to flag transition
TemplateSubHSMState_t nextState; // <- change type to correct enum
......@@ -125,7 +128,7 @@ ES_Event RunBatterySubHSM(ES_Event ThisEvent) {
// initial state
// now put the machine into the actual initial state
nextState = STOP;
makeTransition = TRUE;
ThisEvent.EventType = ES_NO_EVENT;
......@@ -137,10 +140,6 @@ ES_Event RunBatterySubHSM(ES_Event ThisEvent) {
// Edge case to make sure we arent stuck and are fully in the dark
Roach_RightMtrSpeed(-100);
Roach_LeftMtrSpeed(-100);
if((ThisEvent.EventType == FRONT) || (ThisEvent.EventType == FL)|| (ThisEvent.EventType == FR)){
hit = 1;
Roach_LEDSSet(0xFFF);
}
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
nextState = FINISH;
makeTransition = TRUE;
......@@ -150,20 +149,39 @@ ES_Event RunBatterySubHSM(ES_Event ThisEvent) {
// FINISH in the dark
Roach_RightMtrSpeed(0);
Roach_LeftMtrSpeed(0);
if(hit || ((ThisEvent.EventType == FRONT) || (ThisEvent.EventType == FL)|| (ThisEvent.EventType == FR))){
Roach_LEDSSet(0xFFF);
if (((ThisEvent.EventType == FRONT) || (ThisEvent.EventType == FL) || (ThisEvent.EventType == FR))) {
ES_Timer_InitTimer(3, 500);
nextState = MOVE_AWAY;
makeTransition = TRUE;
}
if ((ThisEvent.EventType == BR) || (ThisEvent.EventType == BL) || (ThisEvent.EventType == BACK)) {
ES_Timer_InitTimer(3, 500);
nextState = MOVE_AWAY2;
makeTransition = TRUE;
}
break;
case MOVE_AWAY:
Roach_RightMtrSpeed(50);
Roach_LeftMtrSpeed(50);
case MOVE_AWAY:
Roach_RightMtrSpeed(70);
Roach_LeftMtrSpeed(70);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 3) {
nextState = FINISH;
makeTransition = TRUE;
}
default: // all unhandled states fall into here
break;
case MOVE_AWAY2:
Roach_RightMtrSpeed(-70);
Roach_LeftMtrSpeed(-70);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 3) {
nextState = FINISH;
makeTransition = TRUE;
}
break;
default: // all unhandled states fall into her
if (ThisEvent.EventType == DARK) {
nextState = FINISH;
makeTransition = TRUE;
}
break;
} // end switch on Current State
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment