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]);
124 cmap =
readPGM( pgm_file_name.c_str(),&sx,&sy,
true);
127 nav =
new NavFn(sx,sy);
133 sx = (int)((.001 + size) / (res*.001));
135 nav =
new NavFn(sx,sy);
143 nwin =
new NavWin(sx,sy,
"Potential Field");
160 printf(
"[NavTest] priority increment: %d\n", inc);
167 memcpy(nav->
costarr,cmap,sx*sy);
178 printf(
"Setup: %d ms Plan: %d ms Total: %d ms\n",
179 (
int)(t1-t0), (
int)(t2-t1), (
int)(t2-t0));
185 for (
int i=0; i<nav->
ny*nav->
nx; i++, pp++)
187 if (*pp < 10e7 && *pp > mmax)
192 printf(
"[NavFn] Cells not touched: %d/%d\n", ntot, nav->
nx*nav->
ny);
193 nwin->
maxval = 4*mmax/3/15;
195 while (Fl::check()) {
196 if( Fl::event_key(
'q' ))
215 for (
int i=-
CS/2; i<
CS/2; i++)
218 for (
int j=-
CS/2; j<
CS/2; j++)
222 for (
int i=-
CS/2; i<
CS/2; i++)
225 for (
int j=-
CS/2; j<
CS/2; j++)
235 #define unknown_gray 0xCC // seems to be the value of "unknown" in maps 238 readPGM(
const char *fname,
int *width,
int *height,
bool raw)
240 pm_init(
"navtest",0);
243 pgmfile = fopen(fname,
"r");
246 printf(
"[NavTest] Can't find file %s\n", fname);
250 printf(
"[NavTest] Reading costmap file %s\n", fname);
254 pgm_readpgminit(pgmfile, &ncols, &nrows, &maxval, &format);
255 printf(
"[NavTest] Size: %d x %d\n", ncols, nrows);
260 for (
int i=0; i<ncols*nrows; i++)
263 gray * row(pgm_allocrow(ncols));
267 for (
int ii = 0; ii < nrows; ii++) {
268 pgm_readpgmrow(pgmfile, row, ncols, maxval, format);
271 for (
int jj(ncols - 1); jj >= 0; --jj)
274 cmap[ii*ncols+jj] = v;
284 for (
int jj(ncols - 1); jj >= 0; --jj)
301 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...
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
void display(void fn(NavFn *nav), int n=100)
void setcostunk(COSTTYPE *cmap, int n, int w)