# I am a little confused about costMap and globalPlanner Hi,

for (unsigned int i = 0; i < size_y; ++i)
{
for (unsigned int j = 0; j < size_x; ++j)

{

unsigned char value = new_map->data[index];
costmap_[index] = interpretValue(value);
++index;

}
}


the above is from ros navigation package , /navigation/costmap_2d/plugins/static_layer.cpp 198~206 it update the map according to laserScan.But I am confused why it update costmap from 0 to xy not from x to xy

costmap use the Index(x*nx+y) to represent the two dimensional coordinate,doesn't it?

I have this confusion becuase I see that in globalPlanner,the dijkstra.cpp use index() to getCost,and then it calculatePotentials

dijkstra.cpp 95~116

int k = toIndex(start_x, start_y);
if(precise_)
{
double dx = start_x - (int)start_x, dy = start_y - (int)start_y;
dx = floorf(dx * 100 + 0.5) / 100;
dy = floorf(dy * 100 + 0.5) / 100;
potential[k] = neutral_cost_ * 2 * dx * dy;
potential[k+1] = neutral_cost_ * 2 * (1-dx)*dy;
potential[k+nx_] = neutral_cost_*2*dx*(1-dy);
potential[k+nx_+1] = neutral_cost_*2*(1-dx)*(1-dy);//*/

push_cur(k+2);
push_cur(k-1);
push_cur(k+nx_-1);
push_cur(k+nx_+2);

push_cur(k-nx_);
push_cur(k-nx_+1);
push_cur(k+nx_*2);
push_cur(k+nx_*2+1);
}


when it push_cur,it calls the function getCost() in dijkstra.h.But I find that float c = costs[n] in Function getCost() n represents index(x*nx+y)

So,why we use x and y when we put value into char* costmap,But we use index() get value from costmap. where is the value from costmap to costmap [nx],nx means the x size of map.

help me , Did I make a mistake

I wanna know costmap use x and y or index to represent the values in map

thx~ PS:why MarkDown Grammar  can't be used in this

edit retag close merge delete

Welcome. To format your code you should use the 101010 button (or Ctrl-k). The easiest way to do it is to put the code into the question, highlight it, then hit the button. You can also use single backticks to enclose short bits of code.

one thing, static_layer does not update according to laser_scan but from static maps.

Sort by » oldest newest most voted

Rewriting the first piece of code like this may help with understanding.

int index;
for (unsigned int y = 0; y < size_y; ++i)
{
for (unsigned int x = 0; x < size_x; ++j)
{
index = toIndex(x, y);
char value = new_map->data[index];
costmap_[index] = interpretValue(value);
}
}
`

Not sure if this will even compile, but the point is the two things are equivalent. toIndex function projects 2d coordinates into an index in 1d array, and the value of x and y start from 0. Since the code tries to copy all the value into costmap_, it doesn't really care about the index of each value as long as all the cells are looped through. Therefore it didn't bother to use toIndex.

more