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

# Get (x,y) coordinates of an obstacle from a map

Hello all, I need help,

Can someone tell me how to get the (x,y) coordinates of an obstacle from a 2d map created with gmapping.

I'm working with a Turtlebot robot, ROS Fuerte in Ubuntu.

After retrieving the position ((x,y) coordinates), can we remove the obstacle from the map.

Is it possible to add an obstacle to a created map in a specified position ? if yes How ?

any help is appreciated !

Regards.

edit retag close merge delete

Sort by ยป oldest newest most voted

Hallo avicenna,

actually in occupancy grid maps like in gmapping you dont speak of (x,y) coordinates you are speaking of cells. Of course you can assume that the middlepoint of a cell are you coordinates.

So the Occoupancy Grid map is defined here but the most important is:

The map data, in row-major order, starting with (0,0). Occupancy probabilities are in the range [0,100]. Unknown is -1.

GMapping follows a maximum likelihood convention where a occupancy grid map is a Tri-State:

-1: Unknow

0: Free

100: Occupied

So what you need actually to do is iterating over the cells, check if the probability is 100 and if so print the location:

    for (int width=0; width < occupancy_grid->info.width; ++width)
{
for (int height=0; height < occupancy_grid->info.height; ++height)
{
if(occupancy_grid->data[height*occupancy_grid.info.width + width] > 0)
{
x = width * occupancy_grid->info.resolution + occupancy_grid->info.resolution / 2;
y = height * occupancy_grid->info.resolution + occupancy_grid->info.resolution / 2;
}
}
}


Be careful with is code! I write it out of my memory and its not optimized, with datatypes or even correct. Just an illustration how you can do it. occupancy_grid is here a pointer to a nav_msgs/OccupancyGrid Object.

The code also assumes that your (x,y)-origin is at (0,0). When its not you have to add it to x and y.

more

thanks chwimmer. I understand now. Also thanks for code sample :)

( 2017-05-23 19:10:24 -0500 )edit

can u find a way to do it? i have same problem with you and i cant solve this.

more

did you figure this out?

( 2018-07-05 15:07:01 -0500 )edit

## Stats

Seen: 3,820 times

Last updated: May 22 '17