User Guide

13. // Beep to show that we finished the maze.
14. // Wait for the user to press a button...
15. int i;
i<path_length;16. for(i=0; i++)
nish! Restart the loop.
el circuito, decidir cómo girar y
a select_turn (), tenemos
uidadosamente la intersección a medida que la atraviesa. Tenga en cuenta que
much.
e
traight=0;
N);
s enough to line up our
dark black, we have
d_right);
hat in this
_path() en la sección siguiente. Antes de eso, echemos
es muy simple. Todo lo que hacemos es seguir hasta
rar de acuerdo a nuestros registros. Después de hacer el último giro, el
17. {
18. // SECOND MAIN LOOP BODY
19. }
to the finish. 20. // Follow the last segment up
21. follow_segment();
w we should be at the fi22. // 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
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. This helps us in case we entered the
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);
o th9. // These variables record whether the robot has seen a line t
10. // left, straight ahead, and right, whil examining the current
11. // intersection.
ft=0; 12. unsigned char found_le
nd_s13. unsigned char fou
14. unsigned char found_right=0;
15. // Now read the sensors and check the intersection type.
[5]; 16. unsigned int sensors
17. read_line(sensors,IR_EMITTERS_O
18. // Check for left and right exits.
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);
200 || sensors[3] > 200) 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 ensors[2] > 600 && sensors[3] > 600) . if(sensors[1] > 600 && s
break;
32. // Intersection identification is complete.
n solved, we can follow the existing 33. // If the maze has bee
34. // path. Otherwise, we need to learn the solution.
35 ar dir = select_turn(found_left, found_straight, foun. unsigned ch
6. // Make the 3 turn indicated by the path.
37. turn(dir);
38. // Store the intersection in the path variable.
39. path[path_length] = dir;
40. path_length ++;
ath_length does not 41. // You should check to make sure that the p
42. // exceed the bounds of the array. We’ll ignore t
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 simplify
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.