Hallo SlyD,
wegen der Schleifen und der Blocking Funktion zum Thema: Stopwatch wird ignoriert/ falsch interpretiert:
Ich habe einen neuen Zustand definiert, welcher den Stopwatch bis 5000ms höchzählen enthält. Dieser wird ohne Blocking Funktion übersprungen.
Code:
void behaviour_avoid(void)
{
static uint8_t last_obstacle = LEFT;
static uint8_t obstacle_counter = 0;
switch(avoid.state)
{
case IDLE:
if((obstacle_right && obstacle_left) || (srf_middle_avoid) || (srf_middle_avoid && srf_left_avoid && srf_right_avoid)) // Wenn Sensoren ACS und SRF08
{
avoid.state = AVOID_OBSTACLE_MIDDLE_WAIT;}
else if((obstacle_left) || (srf_left_avoid)) // Sensor Links ACS und SRF08
avoid.state = AVOID_OBSTACLE_LEFT;
else if((obstacle_right) || (srf_right_avoid)) // Sensor Rechts ACS und SRF08
avoid.state = AVOID_OBSTACLE_RIGHT;
break;
case AVOID_OBSTACLE_MIDDLE_WAIT:
moveAtSpeed(0,0);
{
setStopwatch4(400);
startStopwatch4();
avoid.state = AVOID_OBSTACLE_MIDDLE_MIDDLE;
}
setStopwatch5(0);
case AVOID_OBSTACLE_MIDDLE_MIDDLE:
startStopwatch5();
if((getStopwatch5() >=5000))
{
setStopwatch4(400);
startStopwatch4();
avoid.state = AVOID_OBSTACLE_MIDDLE;
}
break;
case AVOID_OBSTACLE_MIDDLE:
avoid.dir = last_obstacle;
avoid.speed_left = AVOID_SPEED_ROTATE;
avoid.speed_right = AVOID_SPEED_ROTATE;
if(!(obstacle_left || obstacle_right || srf_middle_avoid))
{
if(obstacle_counter > 3)
{
obstacle_counter = 0;
setStopwatch4(0);
}
else
setStopwatch4(400);
startStopwatch4();
avoid.state = AVOID_END;
}
break;
case AVOID_OBSTACLE_RIGHT:
avoid.dir = FWD;
avoid.speed_left = AVOID_SPEED_L_ARC_LEFT;
avoid.speed_right = AVOID_SPEED_L_ARC_RIGHT;
if((obstacle_right && obstacle_left) || (srf_middle_avoid))
avoid.state = AVOID_OBSTACLE_MIDDLE_WAIT;
if(!obstacle_right)
{
setStopwatch4(500);
startStopwatch4();
avoid.state = AVOID_END;
}
last_obstacle = RIGHT;
obstacle_counter++;
break;
case AVOID_OBSTACLE_LEFT:
avoid.dir = FWD;
avoid.speed_left = AVOID_SPEED_R_ARC_LEFT;
avoid.speed_right = AVOID_SPEED_R_ARC_RIGHT;
if((obstacle_right && obstacle_left) || (srf_middle_avoid))
avoid.state = AVOID_OBSTACLE_MIDDLE_WAIT;
if(!obstacle_left)
{
setStopwatch4(500);
startStopwatch4();
avoid.state = AVOID_END;
}
last_obstacle = LEFT;
obstacle_counter++;
break;
case AVOID_END:
if(getStopwatch4() > 1000)
{ stopStopwatch4();
setStopwatch4(0);
avoid.state = IDLE;
}
break;
}
}
Übersehe ich da etwas?
Gruß
Mac80
Lesezeichen