scoutos / scout / libscout / src / behaviors / smart_runaround.h @ 2fd5122a
History | View | Annotate | Download (2.32 KB)
1 | 2fd5122a | viki | /**
|
---|---|---|---|
2 | * Copyright (c) 2011 Colony Project
|
||
3 | *
|
||
4 | * Permission is hereby granted, free of charge, to any person
|
||
5 | * obtaining a copy of this software and associated documentation
|
||
6 | * files (the "Software"), to deal in the Software without
|
||
7 | * restriction, including without limitation the rights to use,
|
||
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
9 | * copies of the Software, and to permit persons to whom the
|
||
10 | * Software is furnished to do so, subject to the following
|
||
11 | * conditions:
|
||
12 | *
|
||
13 | * The above copyright notice and this permission notice shall be
|
||
14 | * included in all copies or substantial portions of the Software.
|
||
15 | *
|
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||
23 | * OTHER DEALINGS IN THE SOFTWARE.
|
||
24 | */
|
||
25 | |||
26 | #ifndef _MAZE_SOLVE_H_
|
||
27 | #define _MAZE_SOLVE_H_
|
||
28 | |||
29 | #include "line_follow.h" |
||
30 | /* Details about map:
|
||
31 | * 1 meter = 200 pixels
|
||
32 | * 1 block is a 13x13 pixel section
|
||
33 | * actual meter x meter map has 15 blocks in one row/column
|
||
34 | * # blocks per robot map row = 2*(block per map's row)-1
|
||
35 | */
|
||
36 | |||
37 | // number of blocks in one row/column of robot's map
|
||
38 | #define MAP_LENGTH 29 |
||
39 | |||
40 | class maze_solve: public line_follow |
||
41 | { |
||
42 | public:
|
||
43 | maze_solve(std::string scoutname, Sensors* sensors): |
||
44 | line_follow(scoutname, "maze_solve", sensors) {};
|
||
45 | void run();
|
||
46 | private:
|
||
47 | int choose_direc(int row, int col, int info); |
||
48 | bool solve(int row, int col, int dir); |
||
49 | void turn_from_to(int current_dir, int intended_dir); |
||
50 | bool look_around(int row, int col, int dir); |
||
51 | bool at_destination();
|
||
52 | // functions for changing direction or moving
|
||
53 | void turn_straight(int dir); |
||
54 | void turn_right();
|
||
55 | void spot_turn();
|
||
56 | void turn_left();
|
||
57 | |||
58 | /* Initialize map so that boundaries MAP_LENGTH away
|
||
59 | * from the center. Then car won't go outside of
|
||
60 | * map even if it starts at a boundary and goes to
|
||
61 | * the other side.
|
||
62 | * Rows top to bottom, and columns left to right
|
||
63 | */
|
||
64 | int map[MAP_LENGTH][MAP_LENGTH];
|
||
65 | }; |
||
66 | #endif
|