Code to run the microcontrollers on the R5 competition bot
Dependencies: LineSensors mbed
r5map.h@19:9f4510646c9e, 2015-04-18 (annotated)
- Committer:
- Hypna
- Date:
- Sat Apr 18 03:50:32 2015 +0000
- Revision:
- 19:9f4510646c9e
- Parent:
- 18:2bd595af51d2
Updating navcontroller and r5map
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmar11 | 18:2bd595af51d2 | 1 | #ifndef R5_MAP |
jmar11 | 18:2bd595af51d2 | 2 | #define R5_MAP |
jmar11 | 18:2bd595af51d2 | 3 | |
jmar11 | 18:2bd595af51d2 | 4 | #include <vector> |
jmar11 | 18:2bd595af51d2 | 5 | |
Hypna | 19:9f4510646c9e | 6 | namespace R5Map |
Hypna | 19:9f4510646c9e | 7 | { |
jmar11 | 18:2bd595af51d2 | 8 | |
jmar11 | 18:2bd595af51d2 | 9 | struct position |
jmar11 | 18:2bd595af51d2 | 10 | { |
jmar11 | 18:2bd595af51d2 | 11 | position(int xx = 0, int yy = 0) : x(xx), y(yy) {} |
jmar11 | 18:2bd595af51d2 | 12 | inline bool operator==(const typename ::position& rhs){return ((x==rhs.x) && (y==rhs.y)); } |
jmar11 | 18:2bd595af51d2 | 13 | inline bool operator!=(const typename ::position& rhs){return !operator==(rhs);} |
jmar11 | 18:2bd595af51d2 | 14 | int x,y; |
jmar11 | 18:2bd595af51d2 | 15 | }; |
jmar11 | 18:2bd595af51d2 | 16 | |
jmar11 | 18:2bd595af51d2 | 17 | enum wallState { OPEN, CLOSED, UNKNOWN }; |
jmar11 | 18:2bd595af51d2 | 18 | enum direction { NORTH, EAST, SOUTH, WEST }; |
jmar11 | 18:2bd595af51d2 | 19 | |
jmar11 | 18:2bd595af51d2 | 20 | struct Cell |
jmar11 | 18:2bd595af51d2 | 21 | { |
jmar11 | 18:2bd595af51d2 | 22 | Cell() : north(UNKNOWN), south(UNKNOWN), east(UNKNOWN), west(UNKNOWN), visited(false) {} |
jmar11 | 18:2bd595af51d2 | 23 | wallState north; |
jmar11 | 18:2bd595af51d2 | 24 | wallState south; |
jmar11 | 18:2bd595af51d2 | 25 | wallState east; |
jmar11 | 18:2bd595af51d2 | 26 | wallState west; |
jmar11 | 18:2bd595af51d2 | 27 | bool visited ; |
jmar11 | 18:2bd595af51d2 | 28 | int number; |
jmar11 | 18:2bd595af51d2 | 29 | }; |
jmar11 | 18:2bd595af51d2 | 30 | |
jmar11 | 18:2bd595af51d2 | 31 | class R5Map |
jmar11 | 17:5046b27f5441 | 32 | { |
jmar11 | 18:2bd595af51d2 | 33 | public: |
jmar11 | 18:2bd595af51d2 | 34 | R5Map(int conSize = DEFAULT_SIZE); |
jmar11 | 18:2bd595af51d2 | 35 | void setPosition(position cell); |
jmar11 | 18:2bd595af51d2 | 36 | void setStart(position newStart); |
jmar11 | 18:2bd595af51d2 | 37 | void setFinish(position newFin); |
jmar11 | 18:2bd595af51d2 | 38 | void setWall(position cell, direction dir, wallState state); |
jmar11 | 18:2bd595af51d2 | 39 | void setCurWall(direction dir, wallState state); |
jmar11 | 18:2bd595af51d2 | 40 | void setVisited(position cell); |
jmar11 | 18:2bd595af51d2 | 41 | void setCurVisited(); |
jmar11 | 18:2bd595af51d2 | 42 | position getPosition() const; |
jmar11 | 18:2bd595af51d2 | 43 | position getStart() const; |
jmar11 | 18:2bd595af51d2 | 44 | position getFinish() const; |
jmar11 | 18:2bd595af51d2 | 45 | wallState getWall(position cell, direction dir) const; |
jmar11 | 18:2bd595af51d2 | 46 | wallState getCurWall(direction dir) const; |
jmar11 | 18:2bd595af51d2 | 47 | bool getVisited(position cell) const; |
jmar11 | 18:2bd595af51d2 | 48 | bool getCurVisited() const; |
jmar11 | 18:2bd595af51d2 | 49 | int getSize() const; |
jmar11 | 18:2bd595af51d2 | 50 | void printMap() const; |
jmar11 | 18:2bd595af51d2 | 51 | ~R5Map(); |
jmar11 | 18:2bd595af51d2 | 52 | |
jmar11 | 18:2bd595af51d2 | 53 | private: |
jmar11 | 18:2bd595af51d2 | 54 | static const int DEFAULT_SIZE = 5; |
jmar11 | 18:2bd595af51d2 | 55 | Cell map[7][7]; |
jmar11 | 18:2bd595af51d2 | 56 | int size; |
jmar11 | 18:2bd595af51d2 | 57 | position pos; //X,Y |
jmar11 | 18:2bd595af51d2 | 58 | position start; |
jmar11 | 18:2bd595af51d2 | 59 | position fin; |
jmar11 | 18:2bd595af51d2 | 60 | }; |
Hypna | 19:9f4510646c9e | 61 | } //end namespace |
jmar11 | 18:2bd595af51d2 | 62 | #endif |