Project

General

Profile

Revision 2d697b1f

ID2d697b1f7969fdbd948691959a09157dc1d64e50

Added by Leon about 12 years ago

Adding Doxygen documentation to navigationMap

View differences:

scout/libscout/src/behaviors/navigationMap.cpp
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.cpp
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

  
1 40
#include "navigationMap.h"
2 41

  
3 42
using namespace std;
4 43

  
5
/** @brief Initializes the map */
44
/**
45
 * @brief Initializes the navigation map
46
 *
47
 * Initialize the navigation map. 
48
 * The map itself is represented as a dynamic array of edge arrays
49
 * @param the string name of the scout
50
 */
6 51
navigationMap::navigationMap(string scoutname) : Behavior(scoutname, "navigationMap")
7 52
{
8 53
  /** Initialize Map 
......
105 150
  return;
106 151
}
107 152

  
153
/** @brief FSM implementation*/
108 154
void navigationMap::run()
109 155
{
110 156
  Duration t;
......
140 186
    continue;
141 187
}
142 188

  
189
/**@brief sets the current state to the state associated with the turn made
190
 * @param the Turn that we made from our state
191
 * @return our new State after making the turn 
192
 */
143 193
State navigationMap::update_state(Turn turn_made)
144 194
{
145 195
  Edge* possible_edges = get_outbound_edges(curr_state);
......
160 210
  return -1;//failure to succeed
161 211
}
162 212

  
213
/**@brief returns the predicted time of arrival for our current task
214
 * @return the predicted time of arrival for our current task
215
 */
163 216
Time navigationMap::get_eta()
164 217
{
165 218
  return arrival_time;
166 219
}
167 220

  
221
/**@brief returns the predicted amount of time it will take to finish our task
222
 * @return the predicted amount of time it will take to finish our task
223
 */
168 224
Duration navigationMap::get_time_remaining()
169 225
{
170 226
  return (arrival_time - Time::now());
171 227
}
172 228

  
229
/**@brief returns the current state of the scout in the map
230
 * @return the current State (ie: int) of the scout in the map
231
 */
173 232
State navigationMap::get_state()
174 233
{
175 234
  return curr_state;
176 235
}
177 236

  
237
/**@brief returns the Edges connecting from a given State
238
 * @param the State whose edges we want to get
239
 * @return the Edges connecting from the given State
240
 */
178 241
Edge* navigationMap::get_outbound_edges(State state)
179 242
{
180 243
  return map.at(state-1); 
181 244
}
182 245

  
246
/**@brief uses BFS to find the shortest path to a target State node
247
 * @param the State that we want to get to
248
 * @return a Path struct containing the Turn* to take to get to the target state
249
 */
183 250
Path navigationMap::shortest_path(State target_state)
184 251
{
185 252
  // BFS algorithm
......
231 298
      State new_state = GET_EDGE_STATE(edges[i]);
232 299
      if (new_state != DEADEND && !visited[new_state]) 
233 300
      {
234
        // set visited to the parent of the new state
301
        // set this state in visited as the parent of the new_state
235 302
        visited[new_state] = state;
236 303
        q.push(new_state);
237 304
      }
scout/libscout/src/behaviors/navigationMap.h
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

  
1 40
#ifndef _NAVIGATION_MAP_
2 41
#define _NAVIGATION_MAP_
3 42

  
......
6 45
#include "../Behavior.h"
7 46
//#include "lineDrive.h" // Get turn Macros
8 47

  
48
/** Turn defintions */
9 49
#define ISTRAIGHT	0
10 50
#define ILEFT		1
11 51
#define IRIGHT		2
......
16 56
#define DEADEND -1
17 57
#define ARRAY_SIZE 3
18 58
#define MAX_NODES 12
19

  
59
 
60
/** used to extract information from an encoded Edge */
20 61
#define GET_EDGE_DIR(edge) ((edge)&0x3)
21 62
#define GET_EDGE_STATE(edge) (((edge)>>2)&0xFF)
22 63
#define GET_EDGE_DIST(edge) (((edge)>>10)&0x3FFFFF)
23 64

  
65
/** used to change or build an Edge's information */
24 66
#define SET_EDGE_DIR(dir) ((dir)&0x3)
25 67
#define SET_EDGE_STATE(state) (((state)&0xFF)<<2)
26 68
#define SET_EDGE_DIST(dist) (((dist)&0x3FFFFF)<<10)
......
28 70
#define MAKE_EDGE(dir, state, dist) \
29 71
  SET_EDGE_DIR(dir)+SET_EDGE_STATE(state)+SET_EDGE_DIST(dist)
30 72

  
73
/** an integer with a direction, an associated state, and distance
74
 *  encoded into its bits*/
31 75
typedef int Edge;
76

  
77
/** a simple number representing the number of a node*/
32 78
typedef int State;
79

  
80
/** a number representing a type of turn, as defined above*/
33 81
typedef int Turn;
34 82

  
83
/** a list of turns to follow a path */
35 84
typedef struct{
36 85
  int len;
37 86
  Turn* path;
......
40 89
class navigationMap : Behavior
41 90
{
42 91
  public:
92
    /** Initializes the navigation map */
43 93
    navigationMap(std::string scoutname);
94
    /** Goes through and frees all allocated memory */
44 95
    ~navigationMap();
45 96

  
97
    /** FSM implementation */
46 98
    void run();
47

  
99
    
100
    /** sets the current state to the state associated with the turn made */
48 101
    State update_state(Turn turn_made);
49 102

  
103
    /** returns the predicted time of arrival for our current task */
50 104
    Time get_eta();
105
    /** returns the predicted amount of time it will take to finish our task */
51 106
    Duration get_time_remaining();
52 107

  
108
    /** returns the Edges connecting from a given State */
109
    Edge* get_outbound_edges(State state);  
110

  
111
    /** returns the current state of the scout in the map*/
53 112
    State get_state();
113
    /** uses BFS to find the shortest path to a target State node */
54 114
    Path shortest_path(State target_state);
55 115

  
56
    Edge* get_outbound_edges(State state);        
57

  
58 116
  private:
117
    /** the dynamic array of edge arrays representing individual State nodes */
59 118
    std::vector <Edge*> map;
119
    /** the current State node */
60 120
    State curr_state;
121
    /** the predicted time of arrival for our current task */
61 122
    Time arrival_time;
62 123
};
63 124
#endif

Also available in: Unified diff