scoutos / scout / libscout / src / behaviors / navigationMap.h @ d37cfc69
History | View | Annotate | Download (4.51 KB)
1 |
/**
|
---|---|
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 |
/**
|
27 |
* @file navigationMap.h
|
28 |
* @brief Contains navigation map Behavior declarations and definitions
|
29 |
*
|
30 |
* Contains functions and definitions for the use of
|
31 |
* navigation map Behavior
|
32 |
*
|
33 |
* @author Colony Project, CMU Robotics Club
|
34 |
* @author Priya Deo
|
35 |
* @author Lalitha
|
36 |
* @author James
|
37 |
* @author Leon
|
38 |
**/
|
39 |
|
40 |
#ifndef _NAVIGATION_MAP_
|
41 |
#define _NAVIGATION_MAP_
|
42 |
|
43 |
#include <cstdlib> |
44 |
#include <queue> |
45 |
#include "../Behavior.h" |
46 |
//#include "lineDrive.h" // Get turn Macros
|
47 |
|
48 |
/** Turn defintions */
|
49 |
#define ISTRAIGHT 0 |
50 |
#define ILEFT 1 |
51 |
#define IRIGHT 2 |
52 |
#define IUTURN 3 |
53 |
|
54 |
#define START_STATE 1 |
55 |
|
56 |
#define DEADEND 255 |
57 |
#define ARRAY_SIZE 3 |
58 |
#define MAX_NODES 12 |
59 |
|
60 |
#define SPEED 10 //distance_unit per s |
61 |
#define DROPOFF_TIME 10 //seconds |
62 |
#define TURN_TIME 3 //Seconds |
63 |
#define NUM_ROBOTS 2 |
64 |
#define WAIT_TIME (TURN_TIME * NUM_ROBOTS) //Seconds |
65 |
|
66 |
/** used to extract information from an encoded Edge */
|
67 |
#define GET_EDGE_DIR(edge) ((edge)&0x3) |
68 |
#define GET_EDGE_STATE(edge) (((edge)>>2)&0xFF) |
69 |
#define GET_EDGE_DIST(edge) (((edge)>>10)&0x3FFFFF) |
70 |
|
71 |
/** used to change or build an Edge's information */
|
72 |
#define SET_EDGE_DIR(dir) ((dir)&0x3) |
73 |
#define SET_EDGE_STATE(state) (((state)&0xFF)<<2) |
74 |
#define SET_EDGE_DIST(dist) (((dist)&0x3FFFFF)<<10) |
75 |
|
76 |
#define MAKE_EDGE(dir, state, dist) \
|
77 |
SET_EDGE_DIR(dir)+SET_EDGE_STATE(state)+SET_EDGE_DIST(dist) |
78 |
|
79 |
/** an integer with a direction, an associated state, and distance
|
80 |
* encoded into its bits*/
|
81 |
typedef unsigned int Edge; |
82 |
|
83 |
/** a simple number representing the number of a node*/
|
84 |
typedef unsigned int State; |
85 |
|
86 |
/** a number representing a type of turn, as defined above*/
|
87 |
typedef unsigned int Turn; |
88 |
|
89 |
/** a list of turns to follow a path */
|
90 |
typedef struct{ |
91 |
int len;
|
92 |
Turn* path; |
93 |
} Path; |
94 |
|
95 |
class navigationMap : Behavior |
96 |
{ |
97 |
/** ASCII Representation of the map
|
98 |
*
|
99 |
* 1 2 3 4
|
100 |
* ----|-----------|----------|---------|---------->
|
101 |
* <---|--5--------|--6-------|--7------|--8-------
|
102 |
* | | | |
|
103 |
* 9| 10| 11| 12|
|
104 |
* | | | |
|
105 |
* --- --- --- ---
|
106 |
*/
|
107 |
|
108 |
public:
|
109 |
/** Initializes the navigation map */
|
110 |
navigationMap(std::string scoutname); |
111 |
/** Goes through and frees all allocated memory */
|
112 |
~navigationMap(); |
113 |
|
114 |
/** FSM implementation */
|
115 |
void run();
|
116 |
|
117 |
/** sets the current state to the state associated with the turn made */
|
118 |
State update_state(Turn turn_made); |
119 |
|
120 |
/** returns the predicted time of arrival for our current task */
|
121 |
Time get_eta(); |
122 |
/** returns the predicted amount of time it will take to finish our task */
|
123 |
Duration get_time_remaining(); |
124 |
|
125 |
/** returns the Edges connecting from a given State */
|
126 |
Edge* get_outbound_edges(State state); |
127 |
|
128 |
/** returns the current state of the scout in the map*/
|
129 |
State get_state(); |
130 |
/** uses BFS to find the shortest path to a target State node */
|
131 |
Path shortest_path(State start_state, State target_state); |
132 |
Path shortest_path(State target_state); |
133 |
|
134 |
/** returns the predicted worst case time it will take to travel from src to dest nodes */
|
135 |
Duration get_worst_case_time(State start_state, State target_state); |
136 |
|
137 |
private:
|
138 |
/** the dynamic array of edge arrays representing individual State nodes */
|
139 |
std::vector <Edge*> map; |
140 |
/** the current State node */
|
141 |
State curr_state; |
142 |
/** the predicted time of arrival for our current task */
|
143 |
Time arrival_time; |
144 |
}; |
145 |
#endif
|