16 using namespace navfn;
19 # include <netpbm/pgm.h> 36 gettimeofday(&t0,NULL);
37 double ret = t0.tv_sec * 1000.0;
38 ret += ((double)t0.tv_usec)*0.001;
53 COSTTYPE *
readPGM(
const char *fname,
int *width,
int *height,
bool raw =
false);
55 int main(
int argc,
char **argv)
62 bool got_start_goal =
false;
63 std::string pgm_file_name;
73 pgm_file_name = std::string( argv[ 1 ]) +
".pgm";
74 std::string txt_file_name = std::string( argv[ 1 ]) +
".txt";
76 std::ifstream txt_stream( txt_file_name.c_str() );
81 for(
int i = 0; i < 2; i++ )
83 txt_stream >> name >> x >> y;
84 if( txt_stream && name ==
"Goal:" )
89 else if( txt_stream && name ==
"Start:" )
95 got_start_goal =
true;
96 printf(
"start is %d, %d, goal is %d, %d.\n",
start[ 0 ],
start[ 1 ],
goal[ 0 ],
goal[ 1 ]);
100 printf(
"Failed to open file %s, assuming you didn't want to open a file.\n", txt_file_name.c_str() );
105 if( !got_start_goal )
111 size = atoi(argv[2]);
117 dispn = atoi(argv[4]);
128 cmap =
readPGM( pgm_file_name.c_str(),&sx,&sy,
true);
132 nav =
new NavFn(sx,sy);
138 sx = (int)((.001 + size) / (res*.001));
140 nav =
new NavFn(sx,sy);
148 nwin =
new NavWin(sx,sy,
"Potential Field");
165 printf(
"[NavTest] priority increment: %d\n", inc);
185 printf(
"Time for plan calculation: %d ms\n", (
int)(t1-t0));
196 memcpy(nav->
costarr,cmap,sx*sy);
208 printf(
"Setup: %d ms Plan: %d ms Total: %d ms\n",
209 (
int)(t1-t0), (
int)(t2-t1), (
int)(t2-t0));
216 for (
int i=0; i<nav->
ny*nav->
nx; i++, pp++)
218 if (*pp < 10e7 && *pp > mmax)
223 printf(
"[NavFn] Cells not touched: %d/%d\n", ntot, nav->
nx*nav->
ny);
224 nwin->
maxval = 4*mmax/3/15;
226 while (Fl::check()) {
227 if( Fl::event_key(
'q' ))
235 int k = nav->getCellIndex(gg);
236 int st_nx = nav->st_nx;
237 for (
int i=0; i<900; i++, k--)
239 float npot = nav->potgrid[k];
240 printf(
"Pot: %0.1f\n", npot);
241 printf(
"L: %0.1f R: %0.1f U: %0.1f D: %0.1f\n",
242 nav->potgrid[k-1], nav->potgrid[k+1], nav->potgrid[k-st_nx], nav->potgrid[k+st_nx]);
259 for (
int i=-
CS/2; i<
CS/2; i++)
262 for (
int j=-
CS/2; j<
CS/2; j++)
266 for (
int i=-
CS/2; i<
CS/2; i++)
269 for (
int j=-
CS/2; j<
CS/2; j++)
279 #define unknown_gray 0xCC // seems to be the value of "unknown" in maps 282 readPGM(
const char *fname,
int *width,
int *height,
bool raw)
284 pm_init(
"navtest",0);
287 pgmfile = fopen(fname,
"r");
290 printf(
"[NavTest] Can't find file %s\n", fname);
294 printf(
"[NavTest] Reading costmap file %s\n", fname);
298 pgm_readpgminit(pgmfile, &ncols, &nrows, &maxval, &format);
299 printf(
"[NavTest] Size: %d x %d\n", ncols, nrows);
304 for (
int i=0; i<ncols*nrows; i++)
307 gray * row(pgm_allocrow(ncols));
311 for (
int ii = 0; ii < nrows; ii++) {
312 pgm_readpgmrow(pgmfile, row, ncols, maxval, format);
315 for (
int jj(ncols - 1); jj >= 0; --jj)
318 cmap[ii*ncols+jj] = v;
328 for (
int jj(ncols - 1); jj >= 0; --jj)
347 printf(
"[NavTest] Found %d obstacle cells, %d free cells, %d unknown cells\n", otot, ftot, utot);
void setcostobs(COSTTYPE *cmap, int n, int w)
void setupNavFn(bool keepit=false)
int main(int argc, char **argv)
void setStart(int *start)
Sets the start position for the planner. Note: the navigation cost field computed gives the cost to g...
void setCostmap(const COSTTYPE *cmap, bool isROS=true, bool allow_unknown=true)
Set up the cost array for the planner, usually from ROS.
bool calcNavFnDijkstra(bool atStart=false)
Caclulates the full navigation function using Dijkstra.
TFSIMD_FORCE_INLINE const tfScalar & y() const
void setGoal(int *goal)
Sets the goal position for the planner. Note: the navigation cost field computed gives the cost to ge...
Navigation function class. Holds buffers for costmap, navfn map. Maps are pixel-based. Origin is upper left, x is right, y is down.
COSTTYPE * readPGM(const char *fname, int *width, int *height, bool raw=false)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int calcPath(int n, int *st=NULL)
Calculates the path for at mose <n> cycles.
void display(void fn(NavFn *nav), int n=100)
void setcostunk(COSTTYPE *cmap, int n, int w)
bool propNavFnAstar(int cycles)
Run propagation for <cycles> iterations, or until start is reached using the best-first A* method wit...