Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / behaviors / navigationMap.h @ 2d697b1f

History | View | Annotate | Download (3.7 KB)

1 2d697b1f Leon
/**
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 d8caf546 Priya
#ifndef _NAVIGATION_MAP_
41
#define _NAVIGATION_MAP_
42
43
#include <cstdlib>
44 aa5e4ddc Leon
#include <queue>
45 cccc25c9 Priya
#include "../Behavior.h"
46
//#include "lineDrive.h" // Get turn Macros
47
48 2d697b1f Leon
/** Turn defintions */
49 cccc25c9 Priya
#define ISTRAIGHT        0
50
#define ILEFT                1
51
#define IRIGHT                2
52
#define IUTURN                3
53 d8caf546 Priya
54
#define START_STATE 1
55
56
#define DEADEND -1
57
#define ARRAY_SIZE 3
58 93210a92 Leon
#define MAX_NODES 12
59 2d697b1f Leon
 
60
/** used to extract information from an encoded Edge */
61 d8caf546 Priya
#define GET_EDGE_DIR(edge) ((edge)&0x3)
62
#define GET_EDGE_STATE(edge) (((edge)>>2)&0xFF)
63
#define GET_EDGE_DIST(edge) (((edge)>>10)&0x3FFFFF)
64
65 2d697b1f Leon
/** used to change or build an Edge's information */
66 d8caf546 Priya
#define SET_EDGE_DIR(dir) ((dir)&0x3)
67
#define SET_EDGE_STATE(state) (((state)&0xFF)<<2)
68
#define SET_EDGE_DIST(dist) (((dist)&0x3FFFFF)<<10)
69
70
#define MAKE_EDGE(dir, state, dist) \
71 738e44fb Priya
  SET_EDGE_DIR(dir)+SET_EDGE_STATE(state)+SET_EDGE_DIST(dist)
72
73 2d697b1f Leon
/** an integer with a direction, an associated state, and distance
74
 *  encoded into its bits*/
75 d8caf546 Priya
typedef int Edge;
76 2d697b1f Leon
77
/** a simple number representing the number of a node*/
78 d8caf546 Priya
typedef int State;
79 2d697b1f Leon
80
/** a number representing a type of turn, as defined above*/
81 d8caf546 Priya
typedef int Turn;
82
83 2d697b1f Leon
/** a list of turns to follow a path */
84 738e44fb Priya
typedef struct{
85
  int len;
86
  Turn* path;
87
} Path;
88
89 d8caf546 Priya
class navigationMap : Behavior
90
{
91 738e44fb Priya
  public:
92 2d697b1f Leon
    /** Initializes the navigation map */
93 738e44fb Priya
    navigationMap(std::string scoutname);
94 2d697b1f Leon
    /** Goes through and frees all allocated memory */
95 738e44fb Priya
    ~navigationMap();
96
97 2d697b1f Leon
    /** FSM implementation */
98 738e44fb Priya
    void run();
99 2d697b1f Leon
    
100
    /** sets the current state to the state associated with the turn made */
101 738e44fb Priya
    State update_state(Turn turn_made);
102
103 2d697b1f Leon
    /** returns the predicted time of arrival for our current task */
104 738e44fb Priya
    Time get_eta();
105 2d697b1f Leon
    /** returns the predicted amount of time it will take to finish our task */
106 cccc25c9 Priya
    Duration get_time_remaining();
107 738e44fb Priya
108 2d697b1f Leon
    /** 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*/
112 738e44fb Priya
    State get_state();
113 2d697b1f Leon
    /** uses BFS to find the shortest path to a target State node */
114 738e44fb Priya
    Path shortest_path(State target_state);
115
116
  private:
117 2d697b1f Leon
    /** the dynamic array of edge arrays representing individual State nodes */
118 cccc25c9 Priya
    std::vector <Edge*> map;
119 2d697b1f Leon
    /** the current State node */
120 738e44fb Priya
    State curr_state;
121 2d697b1f Leon
    /** the predicted time of arrival for our current task */
122 738e44fb Priya
    Time arrival_time;
123 d8caf546 Priya
};
124
#endif