1 #ifndef COLLISIONLOOKUP
2 #define COLLISIONLOOKUP
7 namespace HybridAStar {
13 inline void dubinsLookup(
float* lookup) {
15 std::cout <<
"I am building the Dubin's lookup table...";
19 int width = Constants::dubinsWidth / Constants::cellSize;
26 const int headings = Constants::headings;
30 double goal[] = {0, 0, 0};
33 for (
int X = 0; X < width; ++X) {
37 for (
int Y = 0; Y < width; ++Y) {
41 for (
int h0 = 0; h0 < headings; ++h0) {
42 start[2] = Constants::deltaHeadingRad * h0;
45 for (
int h1 = 0; h1 < headings; ++h1) {
46 goal[2] = Constants::deltaHeadingRad * h1;
49 dubins_init(start, goal, Constants::r, &path);
50 lookup[X * headings * headings * width + Y * headings * headings + h0 * headings + h1] = dubins_path_length(&path);
52 if (DEBUG && lookup[X * headings * headings * width + Y * headings * headings + h0 * headings + h1] < sqrt(X * X + Y * Y) * 1.000001) {
53 std::cout << X <<
" | " << Y <<
" | "
54 << Constants::deltaHeadingDeg* h0 <<
" | "
55 << Constants::deltaHeadingDeg* h1 <<
" length: "
56 << lookup[X * headings * headings * width + Y * headings * headings + h0 * headings + h1] <<
"\n";
64 std::cout <<
" done!" << std::endl;
73 inline int sign(
double x) {
74 if (x >= 0) {
return 1; }
80 inline void collisionLookup(Constants::config* lookup) {
82 std::cout <<
"I am building the collision lookup table...";
84 const float cSize = Constants::cellSize;
86 const int size = Constants::bbSize;
124 bool cSpace[size * size];
132 const int positionResolution = Constants::positionResolution;
133 const int positions = Constants::positions;
134 point points[positions];
137 for (
int i = 0; i < positionResolution; ++i) {
138 for (
int j = 0; j < positionResolution; ++j) {
139 points[positionResolution * i + j].x = 1.f / positionResolution * j;
140 points[positionResolution * i + j].y = 1.f / positionResolution * i;
145 for (
int q = 0; q < positions; ++q) {
150 c.x = (double)size / 2 + points[q].x;
151 c.y = (double)size / 2 + points[q].y;
153 p[0].x = c.x - Constants::length / 2 / cSize;
154 p[0].y = c.y - Constants::width / 2 / cSize;
156 p[1].x = c.x - Constants::length / 2 / cSize;
157 p[1].y = c.y + Constants::width / 2 / cSize;
159 p[2].x = c.x + Constants::length / 2 / cSize;
160 p[2].y = c.y + Constants::width / 2 / cSize;
162 p[3].x = c.x + Constants::length / 2 / cSize;
163 p[3].y = c.y - Constants::width / 2 / cSize;
165 for (
int o = 0; o < Constants::headings; ++o) {
166 if (DEBUG) { std::cout <<
"\ndegrees: " << theta * 180.f / M_PI << std::endl; }
169 for (
int i = 0; i < size; ++i) {
170 for (
int j = 0; j < size; ++j) {
171 cSpace[i * size + j] =
false;
176 for (
int j = 0; j < 4; ++j) {
178 temp.x = p[j].x - c.x;
179 temp.y = p[j].y - c.y;
182 nP[j].x = temp.x * cos(theta) - temp.y * sin(theta) + c.x;
183 nP[j].y = temp.x * sin(theta) + temp.y * cos(theta) + c.y;
187 theta += Constants::deltaHeadingRad;
190 for (
int k = 0; k < 4; ++k) {
204 cSpace[Y * size + X] =
true;
205 t.x = end.x - start.x;
206 t.y = end.y - start.y;
212 tDeltaX = 1.f / std::abs(t.x);
218 tDeltaY = 1.f / std::abs(t.y);
225 tMaxX = tDeltaX * (1 - (start.x - (long)start.x));
227 tMaxX = tDeltaX * (start.x - (long)start.x);
231 tMaxY = tDeltaY * (1 - (start.y - (long)start.y));
233 tMaxY = tDeltaY * (start.y - (long)start.y);
236 while ((
int)end.x != X || (
int)end.y != Y) {
238 if (tMaxX < tMaxY && std::abs(X + stepX - (
int)end.x) < std::abs(X - (
int)end.x)) {
239 tMaxX = tMaxX + tDeltaX;
241 cSpace[Y * size + X] =
true;
243 }
else if (tMaxY < tMaxX && std::abs(Y + stepY - (
int)end.y) < std::abs(Y - (
int)end.y)) {
244 tMaxY = tMaxY + tDeltaY;
246 cSpace[Y * size + X] =
true;
247 }
else if (2 >= std::abs(X - (
int)end.x) + std::abs(Y - (
int)end.y)) {
248 if (std::abs(X - (
int)end.x) > std::abs(Y - (
int)end.y)) {
250 cSpace[Y * size + X] =
true;
253 cSpace[Y * size + X] =
true;
257 std::cout <<
"\n--->tie occured, please check for error in script\n";
264 for (
int i = 0; i < size; ++i) {
268 for (
int j = 0; j < size; ++j) {
271 for (
int k = 0; k < size; ++k) {
272 if (cSpace[i * size + k] && !inside) {
277 if (cSpace[i * size + k] && inside) {
283 if (j > hcross1 && j < hcross2 && inside) {
284 cSpace[i * size + j] =
true;
292 for (
int i = 0; i < size; ++i) {
293 for (
int j = 0; j < size; ++j) {
294 if (cSpace[i * size + j]) {
296 lookup[q * Constants::headings + o].pos[count].x = j - (int)c.x;
297 lookup[q * Constants::headings + o].pos[count].y = i - (
int)c.y;
304 lookup[q * Constants::headings + o].length = count;
308 for (
int i = 0; i < size; ++i) {
311 for (
int j = 0; j < size; ++j) {
312 if (cSpace[i * size + j]) {
321 std::cout <<
"\n\nthe center of " << q* Constants::headings + o <<
" is at " << c.x <<
" | " << c.y << std::endl;
323 for (
int i = 0; i < lookup[q * Constants::headings + o].length; ++i) {
324 std::cout <<
"[" << i <<
"]\t" << lookup[q * Constants::headings + o].pos[i].x <<
" | " << lookup[q * Constants::headings + o].pos[i].y << std::endl;
330 std::cout <<
" done!" << std::endl;
This is a collection of constants that are used throughout the project.