We’ll discuss the call to
simplify_path()
in the next section. Before that, let’s take a look at the second
main loop, which is very simple. All we do is drive to the next intersection and turn according to our
records. After doing the last recorded turn, the robot will be one segment away from the finish, which
explains the final
follow_segment()
call in the outline of
maze_solve()
above.
8.e. Simplifying the Solution
After every turn, the length of the recorded path increases by 1. If your maze, for example, has a long
zigzag passageway with no side exits, you’ll see a sequence like ‘RLRLRLRL’ appear on the 3pi’s
LCD. There’s no shortcut that would get you through this section of the path faster than just following
the left hand on the wall strategy. However, whenever we encounter a dead end, we can simplify the
path to something shorter.
Consider the sequence ‘LBL’, where ‘B’ stands for “back” and is the action taken when a dead end
is encountered. This is what happens if there is a left turn that branches off of a straight path and
leads immediately to a dead end. After turning 90° left, 180°, and 90° left again, the net effect is that
the robot is heading in its original direction again. The path can be simplified to a 0° turn: a single ‘S’.
The following diagram depicts this scenario, showing the two functionally equivalent paths from start
to end:
63
64
// Display the path on the LCD.
display_path();
1
2
3
4
5
6
7
8
9
10
11
12
// SECOND MAIN LOOP BODY
follow_segment();
// Drive straight while slowing down, as before.
set_motors(50,50);
delay_ms(50);
set_motors(40,40);
delay_ms(200);
// Make a turn according to the instruction stored in
// path[i].
turn(path[i]);
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
8. Example Project #2: Maze Solving
Page 44 of 85
Содержание 0J5840
Страница 24: ...Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 5 How Your 3pi Works Page 24 of 85...
Страница 67: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 67 of 85...
Страница 77: ...Source code Pololu 3pi Robot User s Guide 2001 2019 Pololu Corporation 10 Expansion Information Page 77 of 85...