# 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 x*y not from x to x*y

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[0] 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

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.