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

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

asked 2015-01-17 05:20:13 -0600

assil gravatar image

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 !

waiting for your answers :)

Regards.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-05-22 01:00:04 -0600

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.

edit flag offensive delete link more

Comments

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

avicenna gravatar image avicenna  ( 2017-05-23 19:10:24 -0600 )edit
0

answered 2017-05-21 20:48:59 -0600

avicenna gravatar image

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

edit flag offensive delete link more

Comments

did you figure this out?

aarontan gravatar image aarontan  ( 2018-07-05 15:07:01 -0600 )edit

Question Tools

4 followers

Stats

Asked: 2015-01-17 05:20:13 -0600

Seen: 3,957 times

Last updated: May 22 '17