forked from Pitt-RAS/micromouse-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigator.h
111 lines (89 loc) · 2.42 KB
/
Navigator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef MICROMOUSE_NAV_H_
#define MICROMOUSE_NAV_H_
#include "data.h"
#include "driver.h"
// Everything in this file MUST be portable code.
//
// These things are NOT portable:
// - Serial, Serial1, Serial2...
// - printf, cin, cout, cerr...
// - Arduino libraries
// - Any libraries at all
// - Anything that requires the Arduino IDE
// - Anything that requires a PC
// - Using the derived_driver variable
//
// The Goal: It should be easy as 1-2-3.
// 1. Copy this file to the mazesim-rewrite source tree.
// 2. Compile the program there.
// 3. Run the simulator on your Linux/Mac/Windows PC.
//
// Example usage:
//
// Navigator<RobotDriver> navigator1;
// navigator1.runDevelopmentCode();
//
// Navigator<CanvasDriver> navigator2;
// navigator2.runDevelopmentCode();
//
template <typename driver_type>
class Navigator
{
private:
driver_type derived_driver;
Driver &driver;
Maze<16, 16> maze;
public:
Navigator();
void driveBox2UnitsLeftTurns();
void driveBox2UnitsRightTurns();
void driveCardboardMaze();
// For development. Fill this method in with whatever you're working on.
// This method is what will be called by mazesim-rewrite.
void runDevelopmentCode();
};
// The methods have to be defined in this file because this is a template.
template <typename driver_type>
Navigator<driver_type>::Navigator() : derived_driver(), driver(derived_driver)
{
}
template <typename driver_type>
void Navigator<driver_type>::driveBox2UnitsLeftTurns()
{
driver.move(kNorth, 2);
driver.move(kWest, 2);
driver.move(kSouth, 2);
driver.move(kEast, 2);
driver.move(kNorth, 0);
}
template <typename driver_type>
void Navigator<driver_type>::driveBox2UnitsRightTurns()
{
driver.move(kNorth, 2);
driver.move(kEast, 2);
driver.move(kSouth, 2);
driver.move(kWest, 2);
driver.move(kNorth, 0);
}
template <typename driver_type>
void Navigator<driver_type>::driveCardboardMaze()
{
driver.move(kNorth, 3);
driver.move(kEast, 1);
driver.move(kWest, 1);
driver.move(kSouth, 1);
driver.move(kEast, 2);
driver.move(kNorth, 1);
driver.move(kSouth, 0);
}
template <typename driver_type>
void Navigator<driver_type>::runDevelopmentCode()
{
// For now, nod left and right to indicate we're running development code.
driver.move(kNorthWest, 0);
driver.move(kNorthEast, 0);
driver.move(kNorthWest, 0);
driver.move(kNorthEast, 0);
driver.move(kNorth, 0);
}
#endif