Pololu 3pi Guía De Usuario página 24

Tabla de contenido
13.
// Beep to show that we finished the maze.
14.
// Wait for the user to press a button...
15.
int i;
16.
for(i=0;
17.
{
18.
// SECOND MAIN LOOP BODY
19.
}
20.
// Follow the last segment up
21.
follow_segment();
22.
// No
23.
}
24. }
El primer bucle principal necesita para seguir un segmento d
recordar el giro en una variable. Para pasar los argumentos correctos
que examinar c
uidadosamente la intersección a medida que la atraviesa. Tenga en cuenta que
existe una excepción especial para encontrar el final del laberinto. El siguiente código funciona
bastante bien, al menos a velocidad lenta que estamos utilizando:
1.
// FIRST MAIN LOOP BODY
2.
follow_segment();
3.
// Drive straight a bit.
4.
// intersection at an angle.
5.
// Note that we are slowing down - this prevents the robot
6.
// from tipping forward too
7.
set_motors(50,50);
8.
delay_ms(50);
9.
// These variables record whether the robot has seen a line t
10.
// left, straight ahead, and right, whil examining the current
11.
// intersection.
12. unsigned char found_le
13. unsigned char fou
14. unsigned char found_right=0;
15.
// Now read the sensors and check the intersection
16. unsigned int sensors
17. read_line(sensors,IR_EMITTERS_O
18.
// Check for left and right
19. if(sensors[0] > 100) found_left = 1;
20. if(sensors[4] > 100) found_right = 1;
21.
// Drive straight a bit more - this i
22.
// wheels with the intersection.
23. set_motors(40,40);
24. delay_ms(200);
25.
// Check for a straight exit.
26. read_line(sensors,IR_EMITTERS_ON);
27. if(sensors[1] > 200 || sensors[2] >
found_straight = 1;
28.
// Check for the ending spot.
29.
// If all three middle sensors are on
30.
// solved the maze.
31
. if(sensors[1] > 600 && s
break;
32.
// Intersection identification is complete.
33.
// If the maze has bee
34.
// path.
Otherwise, we need to learn the solution.
35
. unsigned ch
ar dir = select_turn(found_left, found_straight, foun
3
6.
// Make the
turn indicated by the path.
37. turn(dir);
38.
// Store the intersection in the path variable.
39. path[path_length] = dir;
40. path_length ++;
41.
// You should check to make sure that the p
42.
// exceed the bounds of the array.
43.
// example.
44.
// Simplify the learned path
45. simplify_path();
46.
// Display the path on the LCD.
47. display_path();
Podemos discutir la llamada a
un vistazo al segundo bucle principal, que
la nueva intersección y gi
robot estará a un segmento de la meta, lo que explica la llamada final a follow_segment () en el
maze_solve () anterior.
i<path_length;
i++)
w we should be at the fi
This helps us in case we entered the
much.
ft=0;
nd_s
traight=0;
[5];
N);
exits.
ensors[2] > 600 && sensors[3] > 600)
n solved, we can follow the existing
.
simplify
rar de acuerdo a nuestros registros. Después de hacer el último giro, el
to the
finish.
nish!
Restart the
type.
s enough to line up our
200 || sensors[3] > 200)
dark black, we have
ath_length does not
We'll ignore t
hat in this
en la sección siguiente. Antes de eso, echemos
_path()
es muy simple. Todo lo que hacemos es seguir hasta
loop.
el circuito, decidir cómo girar y
a select_turn (), tenemos
o th
e
d_right);
Tabla de contenido
loading

Productos relacionados para Pololu 3pi

Tabla de contenido