25 PlannerSimple2D::PlannerSimple2D() :
26 occupancyThreshold ( 0.5f ),
27 minStepInReturnedPath (0.4f),
40 std::deque<math::TPoint2D> &path,
42 float maxSearchPathLength )
const 44 #define CELL_ORIGIN 0x0000 45 #define CELL_EMPTY 0x8000 46 #define CELL_OBSTACLE 0xFFFF 47 #define CELL_TARGET 0xFFFE 52 std::vector<uint16_t> grid;
53 int size_x,size_y,i,
n,m;
57 int passCellFound_x = -1,
59 std::vector<uint16_t> pathcells_x,pathcells_y;
87 grid.resize( size_x * size_y );
88 for (
y=0;
y<size_y;
y++)
91 for (
x=0;
x<size_x;
x++)
100 for (
int nEnlargements=0;nEnlargements<obsEnlargement;nEnlargements++)
107 for (
y=2;
y<size_y-2;
y++)
110 int row_1 = (
y+1) * size_x;
111 int row__1 = (
y-1) * size_x;
113 for (
x=2;
x<size_x-2;
x++)
119 if (grid[
x-1+row__1]>=
val ||
120 grid[
x+row__1]>=
val ||
121 grid[
x+1+row__1]>=
val ||
124 grid[
x-1+row_1]>=
val ||
125 grid[
x+row_1]>=
val ||
126 grid[
x+1+row_1]>=
val )
135 for (
y=1;
y<size_y-1;
y++)
138 for (
x=1;
x<size_x-1;
x++)
157 int range_x_min =
min( theMap.
x2idx(origin.
x)-1,theMap.
x2idx(target.
x)-1 );
158 int range_x_max = max( theMap.
x2idx(origin.
x)+1,theMap.
x2idx(target.
x)+1 );
159 int range_y_min =
min( theMap.
y2idx(origin.
y)-1,theMap.
y2idx(target.
y)-1 );
160 int range_y_max = max( theMap.
y2idx(origin.
y)+1,theMap.
y2idx(target.
y)+1 );
165 bool wave1Found=
false, wave2Found =
false;
166 int size_y_1 = size_y-1;
167 int size_x_1 = size_x-1;
168 int longestPathInCellsMetric = 0;
170 range_x_min= max(1, range_x_min - 1 );
171 range_x_max=
min(size_x_1, range_x_max + 1 );
172 range_y_min= max(1, range_y_min - 1 );
173 range_y_max=
min(size_y_1, range_y_max + 1 );
177 for (
y=range_y_min;
y<range_y_max && passCellFound_x==-1;
y++)
180 int row_1 = (
y+1) * size_x;
181 int row__1 = (
y-1) * size_x;
184 for (
x=range_x_min;
x<range_x_max;
x++)
192 v = grid[
x+row__1];
if (
v+2<minNeigh)minNeigh=
v+2;
if (
v-2>maxNeigh &&
v!=
CELL_OBSTACLE)maxNeigh=
v-2;
195 v = grid[
x+row_1];
if (
v+2<minNeigh)minNeigh=
v+2;
if (
v-2>maxNeigh &&
v!=
CELL_OBSTACLE)maxNeigh=
v-2;
197 v = grid[
x-1+row__1];
if ((
v+3)<minNeigh){metric=3;minNeigh=(
v+3);}
if ((
v-3)>maxNeigh &&
v!=
CELL_OBSTACLE) {metric=3;maxNeigh=
v-3;}
198 v = grid[
x+1+row__1];
if ((
v+3)<minNeigh){metric=3;minNeigh=(
v+3);}
if ((
v-3)>maxNeigh &&
v!=
CELL_OBSTACLE) {metric=3;maxNeigh=
v-3;}
199 v = grid[
x-1+row_1];
if ((
v+3)<minNeigh){metric=3;minNeigh=(
v+3);}
if ((
v-3)>maxNeigh &&
v!=
CELL_OBSTACLE) {metric=3;maxNeigh=
v-3;}
200 v = grid[
x+1+row_1];
if ((
v+3)<minNeigh){metric=3;minNeigh=(
v+3);}
if ((
v-3)>maxNeigh &&
v!=
CELL_OBSTACLE) {metric=3;maxNeigh=
v-3;}
204 if ( minNeigh<CELL_EMPTY && maxNeigh>
CELL_EMPTY )
210 longestPathInCellsMetric = 0;
218 grid[
x+
row] = minNeigh + metric;
221 longestPathInCellsMetric = max( longestPathInCellsMetric,
CELL_EMPTY - minNeigh );
228 grid[
x+
row] = maxNeigh - metric;
231 longestPathInCellsMetric = max( longestPathInCellsMetric, maxNeigh -
CELL_EMPTY);
240 notFound = !wave1Found && !wave2Found;
243 if (maxSearchPathLength>0)
244 if ( theMap.
getResolution() * longestPathInCellsMetric * 0.5f > 1.5f*maxSearchPathLength )
252 }
while (!notFound && searching);
264 pathcells_x.reserve( (minNeigh+1)+(
CELL_TARGET-maxNeigh) );
265 pathcells_y.reserve( (minNeigh+1)+(
CELL_TARGET-maxNeigh) );
266 x = passCellFound_x;
y = passCellFound_y;
271 pathcells_x.push_back(
x);
272 pathcells_y.push_back(
y);
275 static signed char dx=0,dy=0;
276 if ((
c=grid[
x-1+size_x*
y])<
v) {
v=
c; dx=-1; dy= 0; }
277 if ((
c=grid[
x+1+size_x*
y])<
v) {
v=
c; dx= 1; dy= 0; }
278 if ((
c=grid[
x+size_x*(
y-1)])<
v) {
v=
c; dx= 0; dy=-1; }
279 if ((
c=grid[
x+size_x*(
y+1)])<
v) {
v=
c; dx= 0; dy= 1; }
281 if ((
c=grid[
x-1+size_x*(
y-1)])<
v) {
v=
c; dx=-1; dy= -1; }
282 if ((
c=grid[
x+1+size_x*(
y-1)])<
v) {
v=
c; dx= 1; dy= -1; }
283 if ((
c=grid[
x-1+size_x*(
y+1)])<
v) {
v=
c; dx=-1; dy= 1; }
284 if ((
c=grid[
x+1+size_x*(
y+1)])<
v) {
v=
c; dx= 1; dy= 1; }
294 n = pathcells_x.size(); m =
n / 2;
298 pathcells_x[i] = pathcells_x[
n-1-i];
299 pathcells_x[
n-1-i] =
v;
302 pathcells_y[i] = pathcells_y[
n-1-i];
303 pathcells_y[
n-1-i] =
v;
308 x = passCellFound_x;
y = passCellFound_y;
313 pathcells_x.push_back(
x);
314 pathcells_y.push_back(
y);
317 static signed char dx=0,dy=0;
337 n = pathcells_x.size();
339 float last_xx = origin.
x, last_yy = origin.
y;
343 xx = theMap.
idx2x( pathcells_x[i] );
344 yy = theMap.
idx2y( pathcells_y[i] );
float getXMax() const
Returns the "x" coordinate of right side of grid map.
float getYMin() const
Returns the "y" coordinate of top side of grid map.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
unsigned __int16 uint16_t
float getResolution() const
Returns the resolution of the grid map.
float robotRadius
The aproximate robot radius used in the planification. Default is 0.35m.
float minStepInReturnedPath
The minimum distance between points in the returned found path (default=0.4); Notice that full grid r...
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...
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
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.
float occupancyThreshold
The maximum occupancy probability to consider a cell as an obstacle, default=0.5. ...
unsigned int getSizeX() const
Returns the horizontal size of grid map in cells count.
A class used to store a 2D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
A class for storing an occupancy grid map.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
GLenum GLenum GLvoid * row
float idx2y(const size_t cy) const
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.
int x2idx(float x) const
Transform a coordinate value into a cell index.
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.