
Capitolo 10 - Il movimento autonomo 173
// restituisce true se viene rilevato un determinato ostacolo
boolean lookForObstacle(int obstacle)
{
switch(obstacle) {
case OBST_FRONT_EDGE: return irEdgeDetect(DIR_LEFT) &&
irEdgeDetect(DIR_RIGHT);
case OBST_LEFT_EDGE: return irEdgeDetect(DIR_LEFT);
case OBST_RIGHT_EDGE: return irEdgeDetect(DIR_RIGHT);
case OBST_FRONT: return lookAt(lookAngles[DIR_CENTER]) <= MIN_DISTANCE;
}
return false;
}
// restituisce la distanza degli oggetti in base all'angolo dato
// questa versione fa ruotare il robot
int lookAt(int angle)
{
moveRotate(angle); // fa ruotare il robot
int distance, samples;
long ...