ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

I am a little confused about costMap and globalPlanner

asked 2017-09-05 05:33:42 -0600

updated 2017-09-06 06:41:23 -0600

bvbdort gravatar image


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);


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);
    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);//*/



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

edit retag flag offensive 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.

jayess gravatar image jayess  ( 2017-09-05 09:46:43 -0600 )edit

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

naveedhd gravatar image naveedhd  ( 2017-09-07 02:45:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-09-06 11:30:19 -0600

huanxiner gravatar image

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.

edit flag offensive delete link more


I have figure it out ,thank you ! But now I have met another problem failed to get a plan

pengjiawei gravatar image pengjiawei  ( 2017-09-07 03:49:28 -0600 )edit

Question Tools

1 follower


Asked: 2017-09-05 05:33:42 -0600

Seen: 410 times

Last updated: Sep 06 '17