25 PlannerSimple2D::PlannerSimple2D()
26 : occupancyThreshold(0.5f), minStepInReturnedPath(0.4f), robotRadius(0.35f)
35 const CPose2D& target_, std::deque<math::TPoint2D>& path,
bool& notFound,
36 float maxSearchPathLength)
const
38 #define CELL_ORIGIN 0x0000
39 #define CELL_EMPTY 0x8000
40 #define CELL_OBSTACLE 0xFFFF
41 #define CELL_TARGET 0xFFFE
46 std::vector<uint16_t> grid;
47 int size_x, size_y, i,
n, m;
51 int passCellFound_x = -1, passCellFound_y = -1;
52 std::vector<uint16_t> pathcells_x, pathcells_y;
81 grid.resize(size_x * size_y);
82 for (
y = 0;
y < size_y;
y++)
85 for (
x = 0;
x < size_x;
x++)
96 for (
int nEnlargements = 0; nEnlargements < obsEnlargement; nEnlargements++)
103 for (
y = 2;
y < size_y - 2;
y++)
105 int row =
y * size_x;
106 int row_1 = (
y + 1) * size_x;
107 int row__1 = (
y - 1) * size_x;
109 for (
x = 2;
x < size_x - 2;
x++)
115 if (grid[
x - 1 + row__1] >=
val || grid[
x + row__1] >=
val ||
116 grid[
x + 1 + row__1] >=
val || grid[
x - 1 +
row] >=
val ||
117 grid[
x + 1 +
row] >=
val || grid[
x - 1 + row_1] >=
val ||
118 grid[
x + row_1] >=
val || grid[
x + 1 + row_1] >=
val)
128 for (
y = 1;
y < size_y - 1;
y++)
130 int row =
y * size_x;
131 for (
x = 1;
x < size_x - 1;
x++)
139 grid[theMap.
x2idx(origin.
x) + size_x * theMap.
y2idx(origin.
y)] =
141 grid[theMap.
x2idx(target.
x) + size_x * theMap.
y2idx(target.
y)] =
153 max(theMap.
x2idx(origin.
x) + 1, theMap.
x2idx(target.
x) + 1);
157 max(theMap.
y2idx(origin.
y) + 1, theMap.
y2idx(target.
y) + 1);
162 bool wave1Found =
false, wave2Found =
false;
163 int size_y_1 = size_y - 1;
164 int size_x_1 = size_x - 1;
165 int longestPathInCellsMetric = 0;
167 range_x_min = max(1, range_x_min - 1);
168 range_x_max =
min(size_x_1, range_x_max + 1);
169 range_y_min = max(1, range_y_min - 1);
170 range_y_max =
min(size_y_1, range_y_max + 1);
174 for (
y = range_y_min;
y < range_y_max && passCellFound_x == -1;
y++)
176 int row =
y * size_x;
177 int row_1 = (
y + 1) * size_x;
178 int row__1 = (
y - 1) * size_x;
181 for (
x = range_x_min;
x < range_x_max;
x++)
189 v = grid[
x + row__1];
190 if (
v + 2 < minNeigh) minNeigh =
v + 2;
193 v = grid[
x - 1 +
row];
194 if (
v + 2 < minNeigh) minNeigh =
v + 2;
197 v = grid[
x + 1 +
row];
198 if (
v + 2 < minNeigh) minNeigh =
v + 2;
202 if (
v + 2 < minNeigh) minNeigh =
v + 2;
206 v = grid[
x - 1 + row__1];
207 if ((
v + 3) < minNeigh)
217 v = grid[
x + 1 + row__1];
218 if ((
v + 3) < minNeigh)
228 v = grid[
x - 1 + row_1];
229 if ((
v + 3) < minNeigh)
239 v = grid[
x + 1 + row_1];
240 if ((
v + 3) < minNeigh)
253 if (minNeigh < CELL_EMPTY && maxNeigh >
CELL_EMPTY)
259 longestPathInCellsMetric = 0;
267 grid[
x +
row] = minNeigh + metric;
270 longestPathInCellsMetric = max(
271 longestPathInCellsMetric,
CELL_EMPTY - minNeigh);
278 grid[
x +
row] = maxNeigh - metric;
281 longestPathInCellsMetric = max(
282 longestPathInCellsMetric, maxNeigh -
CELL_EMPTY);
292 notFound = !wave1Found && !wave2Found;
295 if (maxSearchPathLength > 0)
296 if (theMap.
getResolution() * longestPathInCellsMetric * 0.5f >
297 1.5f * maxSearchPathLength)
306 }
while (!notFound && searching);
309 if (notFound)
return;
320 pathcells_y.reserve((minNeigh + 1) + (
CELL_TARGET - maxNeigh));
328 pathcells_x.push_back(
x);
329 pathcells_y.push_back(
y);
332 static signed char dx = 0, dy = 0;
333 if ((
c = grid[
x - 1 + size_x *
y]) <
v)
339 if ((
c = grid[
x + 1 + size_x *
y]) <
v)
345 if ((
c = grid[
x + size_x * (
y - 1)]) <
v)
351 if ((
c = grid[
x + size_x * (
y + 1)]) <
v)
358 if ((
c = grid[
x - 1 + size_x * (
y - 1)]) <
v)
364 if ((
c = grid[
x + 1 + size_x * (
y - 1)]) <
v)
370 if ((
c = grid[
x - 1 + size_x * (
y + 1)]) <
v)
376 if ((
c = grid[
x + 1 + size_x * (
y + 1)]) <
v)
391 n = pathcells_x.size();
393 for (i = 0; i < m; i++)
396 pathcells_x[i] = pathcells_x[
n - 1 - i];
397 pathcells_x[
n - 1 - i] =
v;
400 pathcells_y[i] = pathcells_y[
n - 1 - i];
401 pathcells_y[
n - 1 - i] =
v;
412 pathcells_x.push_back(
x);
413 pathcells_y.push_back(
y);
416 static signed char dx = 0, dy = 0;
417 c = grid[
x - 1 + size_x *
y];
424 c = grid[
x + 1 + size_x *
y];
431 c = grid[
x + size_x * (
y - 1)];
438 c = grid[
x + size_x * (
y + 1)];
446 c = grid[
x - 1 + size_x * (
y - 1)];
453 c = grid[
x + 1 + size_x * (
y - 1)];
460 c = grid[
x - 1 + size_x * (
y + 1)];
467 c = grid[
x + 1 + size_x * (
y + 1)];
484 n = pathcells_x.size();
486 float last_xx = origin.
x, last_yy = origin.
y;
487 for (i = 0; i <
n; i++)
490 xx = theMap.
idx2x(pathcells_x[i]);
491 yy = theMap.
idx2y(pathcells_y[i]);
A class for storing an occupancy grid map.
float getResolution() const
Returns the resolution of the grid map.
float getYMin() const
Returns the "y" coordinate of top side of grid map.
float idx2y(const size_t cy) const
unsigned int getSizeX() const
Returns the horizontal size of grid map in cells count.
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
int x2idx(float x) const
Transform a coordinate value into a cell index.
float getXMax() const
Returns the "x" coordinate of right side of grid map.
float getYMax() const
Returns the "y" coordinate of bottom side of grid map.
unsigned int getSizeY() const
Returns the vertical size of grid map in cells count.
float getXMin() const
Returns the "x" coordinate of left side of grid map.
float idx2x(const size_t cx) const
Transform a cell index into a coordinate value.
void computePath(const mrpt::maps::COccupancyGridMap2D &theMap, const mrpt::poses::CPose2D &origin, const mrpt::poses::CPose2D &target, std::deque< mrpt::math::TPoint2D > &path, bool ¬Found, float maxSearchPathLength=-1) const
This method compute the optimal path for a circular robot, in the given occupancy grid map,...
float occupancyThreshold
The maximum occupancy probability to consider a cell as an obstacle, default=0.5
float robotRadius
The aproximate robot radius used in the planification.
float minStepInReturnedPath
The minimum distance between points in the returned found path (default=0.4); Notice that full grid r...
A class used to store a 2D point.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
GLenum GLenum GLvoid * row
This base provides a set of functions for maths stuff.
T square(const T x)
Inline function for the square of a number.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int16 uint16_t