Just to give u a little background of what I am doing, I am currently programming my vehicle to wall-hug a maze. My idea is that my vehicle does a check at start whether or not it will move in clockwise or anti clockwise direction. The thing I am not so sure about is the placement of my flag in my codes. Some of my friends questioned why I have 2 flags in my code, this made me unsure of whether my codes/logic is right. Refer to my codes for more info. If it is wrong, let me know how I can correct it. Thanks.
if( g_NavState == NAV_NONE ){ //if vehicle is not moving
if(state.order.bLeft==TRUE){ //left sensor detects obstacle, moves clockwise.
g_NavState = NAV_FRONT;
g_MoveStateCmd = MOVE_FWD;
flag1 = 1; //Unsure about this flag
}
else if(state.order.bRight==TRUE){ //right sensor detects obstacle, moves anti clockwise
g_NavState = NAV_FRONT;
g_MoveStateCmd = MOVE_FWD;
flag2 = 1;//Unsure about this flag
}
}
else if(g_NavState==NAV_FRONT){ //while going front
if(state.order.bFrontLeft==FALSE && state.order.bLeft==FALSE && state.order.bBackLeft==FALSE && flag1 == 1){
for(int iter=0;iter<1000000;iter++){
}
g_NavState = NAV_FL;
g_MoveStateCmd = MOVE_FRONT_LEFT;
}
else if(state.order.bFrontRight==FALSE && state.order.bRight==FALSE && state.order.bBackRight==FALSE && flag2 == 1){ /*Anti-Clockwise*/
for(int iter=0;iter<1000000;iter++){
}
g_NavState = NAV_FR;
g_MoveStateCmd = MOVE_FRONT_RIGHT;
}