Between the PID code and the intersection detection, there are now about six more parameters that
could be adjusted. We’ve picked values here that allow 3pi to solve the maze at a safe, controlled
speed; try increasing the speed and you will quickly run in to lots of problems that you’ll have to handle
with more complicated code.
Putting the C files and header files into your project is easy with Atmel Studio. On the right side of your
screen, in the “Solution Explorer” pane, you should see a list of files in your project. Right click on the
name of your project and you will have the option to add files to the list. When you build your project,
Atmel Studio will automatically compile all C files in the project together to produce a single hex file.
8.c. Left Hand on the Wall
The basic strategy for solving a non-looped maze is called “left hand on the wall”. Imagine walking
through a real labyrinth – a human-sized maze built with stone walls – while keeping your left hand on
the wall at all times. You’ll turn left whenever possible and only turn right at an intersection if there is
no other exit. Sometimes, when you reach a dead end, you’ll turn 180 degrees to the right and start
walking back the way you came. Eventually, as long as there are no loops, your hand will travel along
each length of wall in the entire labyrinth exactly once, and you’ll find your way back to the entrance.
If there is a room somewhere in the labyrinth with a monster or some treasure, you’ll find that on the
way, since you’ll travel down every hallway exactly twice. We use this simple, reliable strategy in our
3pi maze solving example:
The values returned by
select_turn()
correspond to the values used by
turn()
, so these functions will
work nicely together in our main loop.
63
64
65
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// This function decides which way to turn during the learning phase of
// maze solving.
It uses the variables found_left, found_straight, and
// found_right, which indicate whether there is an exit in each of the
// three directions, applying the "left hand on the wall" strategy.
char
select_turn(unsigned
char
found_left, unsigned
char
found_straight,
unsigned
char
found_right)
{
// Make a decision about how to turn.
The following code
// implements a left-hand-on-the-wall strategy, where we always
// turn as far to the left as possible.
if
(found_left)
return
'L'
;
else if
(found_straight)
return
'S'
;
else if
(found_right)
return
'R'
;
else
return
'B'
;
}
Pololu 3pi Robot User’s Guide
© 2001–2019 Pololu Corporation
8. Example Project #2: Maze Solving
Page 41 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...