LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Konstantinos Katsaros | 3 * Copyright (c) 2011 Konstantinos Katsaros |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Konstantinos Katsaros <K.Katsaros@surrey.ac.uk> | 18 * Author: Konstantinos Katsaros <K.Katsaros@surrey.ac.uk> |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 | 22 |
| 23 /** |
| 24 * |
| 25 * The CLWPR MAP is indented as a navigation system to provide information about |
| 26 * the underlying road topology. The current implementation ony supports grid ne
tworks. |
| 27 * The GridMap class is developed as an initial and simplistic navigation system
. |
| 28 * Due to the limitations set by the CLWPR protocol that only allows a 8-bit ide
ntification |
| 29 * of the road, which comprises of two 4-bit parts for x- and y-axis, respective
ly, the maximum |
| 30 * grid size is set to 15x15. |
| 31 * |
| 32 * \TODO |
| 33 * Import some kind of open API for navigation (google.maps, openstreetmap, etc) |
| 34 * |
| 35 */ |
| 36 |
23 #ifndef CLWPR_MAP_H_ | 37 #ifndef CLWPR_MAP_H_ |
24 #define CLWPR_MAP_H_ | 38 #define CLWPR_MAP_H_ |
25 | 39 |
26 // MAX Road Network 15 X 15 | 40 // MAX Road Network 15 X 15 set by CLWPR constraints |
27 #define MAX_DIAMENSION 15 | 41 #define MAX_DIAMENSION 15 |
28 #define ROADERR 15 | 42 #define ROADERR 15 |
29 | 43 |
30 #include <stdint.h> | 44 #include <stdint.h> |
31 #include <stdio.h> | 45 #include <stdio.h> |
32 #include <iostream> | 46 #include <iostream> |
33 #include "ns3/vector.h" | 47 #include "ns3/vector.h" |
34 #include <utility> | 48 #include <utility> |
35 #include "ns3/object.h" | 49 #include "ns3/object.h" |
36 namespace ns3 { | 50 namespace ns3 { |
37 | 51 |
38 | 52 |
39 class GridMap : public Object | 53 class GridMap : public Object |
40 { | 54 { |
41 private: | 55 private: |
42 double m_x; //x co-ordinate of vehicle | 56 double m_x; ///< x co-ordinate of vehicle [0-15] |
43 double m_y; // Data member of vegicle | 57 double m_y; ///< y co-ordinate of vehicle [0-15] |
44 » » uint8_t m_roadID; | 58 » uint8_t m_roadID; ///< the ID of the road |
45 » » int m_xd; //x co-ordinate of road | 59 » int m_xd; ///< local x co-ordinate of road |
46 » » int m_yd; //y co-ordinate of road | 60 » int m_yd; ///< local y co-ordinate of road |
47 » » int m_xMax, m_yMax; | 61 » int m_xMax, m_yMax; ///< max values for current map |
48 » » int m_dist; //Distance between blocks | 62 » int m_dist; ///< distance between blocks |
49 » » std::pair<double, double> m_waypoints[MAX_DIAMENSION][MAX_DIAME
NSION]; | 63 » std::pair<double, double> m_waypoints[MAX_DIAMENSION][MAX_DIAMENSION];
///< the location of the junctions |
50 | 64 |
51 » » void InitWayPoitns(); //Set waypoits | 65 » /** |
52 » » int FindWPX (Vector p, int r_index); | 66 » * This function initialises the waypoints (junctions) |
53 » » int FindWPY (Vector p, int r_index); | 67 » * |
| 68 » */ |
| 69 » void InitWayPoitns(); |
| 70 |
| 71 » /** |
| 72 * This function returns the waypoint is closer to |
| 73 * a node on the x-axis |
| 74 * |
| 75 * @param p The position Vector of the node |
| 76 * @param r_index the Road index it is moving (y-axis) |
| 77 * @return the x-axis waypoint closer to the node position |
| 78 */ |
| 79 » int FindWPX (Vector p, int r_index); |
| 80 |
| 81 /** |
| 82 * This function returns the waypoint is closer to |
| 83 * a node on the y-axis |
| 84 * |
| 85 * @param p The position Vector of the node |
| 86 * @param r_index the Road index it is moving (x-axis) |
| 87 * @return the y-axis waypoint closer to the node position |
| 88 */ |
| 89 » int FindWPY (Vector p, int r_index); |
54 | 90 |
55 public: | 91 public: |
56 » » static TypeId GetTypeId (void); | 92 » static TypeId GetTypeId (void); |
57 » » GridMap(); | 93 |
58 » » GridMap(int x, int y, int d); | 94 » /** |
59 » » ~GridMap(); | 95 » * Default Constructor |
60 » » uint8_t FindRoadID(int r_x, int r_y); | 96 » */ |
61 » » int GetRoadXFromID (uint8_t r_id); | 97 » GridMap(); |
62 » » int GetRoadYFromID (uint8_t r_id); | 98 |
63 » » void SetRoadXFromVehicle(double v_x); | 99 » /** |
64 » » void SetRoadYFromVehicle(double v_y); | 100 » * Constructor for specific dimensions |
65 » » int GetRoadXId(); | 101 » * Currently only square blocks are formed. Could use a 4th parameter
for |
66 » » int GetRoadYId(); | 102 » * different x,y block sizes |
67 » » double GetCurvemetricDistance(Vector pos_a, int x_a, int y_a,
Vector pos_b, int x_b, int y_b); | 103 » * |
68 » » void GetNLOSDistance(Vector pos_a, int x_a, int y_a, Vector po
s_b, int x_b, int y_b, double &dist1, double &dist2); | 104 » * @param x the number of x-axis roads |
69 » » int GetRoadXFromVehicle(double v_x); | 105 » * @param y the number of y-axis roads |
70 » » int GetRoadYFromVehicle(double v_y); | 106 » * @param d the distance between two intersections |
| 107 » */ |
| 108 » GridMap(int x, int y, int d); |
| 109 |
| 110 » /** |
| 111 » * Default Destructor |
| 112 » */ |
| 113 » ~GridMap(); |
| 114 |
| 115 /** |
| 116 * Method to return the road id using the x,y parts |
| 117 * |
| 118 * @param r_x the x-axis part (4 MSB of ID) |
| 119 * @param r_y the y-axis part (4 LSB of ID) |
| 120 * @return the road ID |
| 121 */ |
| 122 » uint8_t FindRoadID(int r_x, int r_y); |
| 123 |
| 124 /** |
| 125 * Method to return the x-axis part of the road ID |
| 126 * |
| 127 * @param r_id the road ID |
| 128 * @return the x-axis ID (4 MSB of r_id) |
| 129 */ |
| 130 » int GetRoadXFromID (uint8_t r_id); |
| 131 |
| 132 /** |
| 133 * Method to return the y-axis part of the road ID |
| 134 * |
| 135 * @param r_id the road ID |
| 136 * @return the y-axis ID (4 LSB of r_id) |
| 137 */ |
| 138 » int GetRoadYFromID (uint8_t r_id); |
| 139 |
| 140 » /** |
| 141 * Method to to set the local x-axis road co-ordinate |
| 142 * |
| 143 * @param v_x the vehicle's x co-ordinate |
| 144 */ |
| 145 » void SetRoadXFromVehicle(double v_x); |
| 146 |
| 147 /** |
| 148 * Method to to set the local y-axis road co-ordinate |
| 149 * |
| 150 * @param v_y the vehicle's y co-ordinate |
| 151 */ |
| 152 » void SetRoadYFromVehicle(double v_y); |
| 153 |
| 154 » /** |
| 155 » * Simple getter for the local axis road co-ordinate |
| 156 » * |
| 157 » * @return the local x-axis co-ordinate |
| 158 » */ |
| 159 » int GetRoadXId(); |
| 160 |
| 161 /** |
| 162 * Simple getter for the local axis road co-ordinate |
| 163 * |
| 164 * @return the local y-axis co-ordinate |
| 165 */ |
| 166 » int GetRoadYId(); |
| 167 |
| 168 » /** |
| 169 » * This method calculates the distance between two nodes following |
| 170 » * the road (waypoints). Also known as curvemetric distance. |
| 171 » * |
| 172 » * @param pos_a the position Vector of node A |
| 173 » * @param x_a the x-axis road co-ordinate of node A |
| 174 » * @param y_a the y-axis road co-ordinate of node A |
| 175 * @param pos_b the position Vector of node B |
| 176 * @param x_b the x-axis road co-ordinate of node B |
| 177 * @param y_b the y-axis road co-ordinate of node B |
| 178 » * @return the curvemetric distance |
| 179 » */ |
| 180 » double GetCurvemetricDistance(Vector pos_a, int x_a, int y_a, Vector p
os_b, int x_b, int y_b); |
| 181 |
| 182 » /** |
| 183 » * This method calculates the LOS and NLOS distance between two nodes
that is mentioned to be |
| 184 » * used by the propagation loss model utilising visibility (buildings) |
| 185 » * See WINNER Propagation models --> https://www.ist-winner.org/WINNER
2-Deliverables/D1.1.2v1.1.pdf |
| 186 » * |
| 187 » * @param pos_a the position Vector of node A |
| 188 » * @param x_a the x-axis road co-ordinate of node A |
| 189 » * @param y_a the y-axis road co-ordinate of node A |
| 190 » * @param pos_b the position Vector of node B |
| 191 » * @param x_b the x-axis road co-ordinate of node B |
| 192 » * @param y_b the y-axis road co-ordinate of node B |
| 193 » * @param &dist1 the LOS component |
| 194 » * @param &dist2 the NLOS component |
| 195 » */ |
| 196 » void GetNLOSDistance(Vector pos_a, int x_a, int y_a, Vector pos_b, int
x_b, int y_b, double &dist1, double &dist2); |
| 197 |
| 198 » /** |
| 199 » * Simple getter to return the local x-axis road id |
| 200 » * from the vehicle position |
| 201 » * |
| 202 » * @param v_x the x-axis co-ordinate of vehicles position |
| 203 » * @return the x-axis road id |
| 204 » */ |
| 205 » int GetRoadXFromVehicle(double v_x); |
| 206 |
| 207 /** |
| 208 * Simple getter to return the local y-axis road id |
| 209 * from the vehicle position |
| 210 * |
| 211 * @param v_y the y-axis co-ordinate of vehicles position |
| 212 * @return the y-axis road id |
| 213 */ |
| 214 » int GetRoadYFromVehicle(double v_y); |
71 }; | 215 }; |
72 } // namespace ns3 | 216 } // namespace ns3 |
73 | 217 |
74 #endif /* CLWPR_MAP_H_ */ | 218 #endif /* CLWPR_MAP_H_ */ |
LEFT | RIGHT |