Ask Your Question

how to get real-time access to grid data from map generated by gmapping?

asked 2016-02-21 23:58:50 -0500

edmond320 gravatar image

Hello everyone,

I'm trying to simulate robot exploration in gazebo using gmapping. Now I'm able to generate the map using SLAM and save it using map_server.

I would like to ask how do I get access to the individual grid data? for example I need to detect the frontier grids and calculate its distance to the current position of the robot, how do I achieve this in ROS? I suppose it should be a matrix or something similar, any help or suggestion would be much appreciated!

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-22 06:19:29 -0500

donmrsir gravatar image


I think that the information you are looking for, is published in the topic /map. If you take a look to the gmapping documentation , you will see that gmapping, publish the occupancy grid information, in the format of a message of the type, in the topic /map. So, you should just subscribe to that topic, to get the information you are looking for.

Hope this helps you!

edit flag offensive delete link more


Thanks for your reply. I've checked that out, but the map data there is a 1 dimention data and I could not figure out how to convert it to the actual 2 dimention array. Do you know how to do this?

edmond320 gravatar image edmond320  ( 2016-02-24 06:37:16 -0500 )edit

Hi!, did you look at the content of the OccupancyGrid Message?, following the documentation this message, " represents a 2-D grid map, in which each cell represents the probability of occupancy.". So i think it should be a 2D info. Are you sure you are looking at the correct topic?

donmrsir gravatar image donmrsir  ( 2016-02-24 08:40:46 -0500 )edit

hi,i am having the same issue,occupancy grid does say its 2D but int8[] data is one dimensional which only gives information if the cell if empty or not but i cant seem to find the (x,y) coordinates related to each of the cell.Do i have to do it myself by using loops or some other library maybe?

az gravatar image az  ( 2018-03-01 03:13:12 -0500 )edit

@az As for my case, I implemented my own conversion and it's a easy one: def convertTo2DArray(): for i in range(map_width): for j in range(map_heigh) slam_map[i][j] = raw_map[i + j * map_width]

where the width and height are obtain from map message received from 'map' topic.

edmond320 gravatar image edmond320  ( 2018-03-05 21:45:39 -0500 )edit

Thanks alot!

az gravatar image az  ( 2018-03-10 15:14:12 -0500 )edit

Essentially, the grid data is in row-major index format - which means if the width of the row (which you can get from is 1000,[0] = [0,0][356] = [356,0][1000]= [0,1][72653]=[653,72][ i ]=[(i%width),(int)(i/width)]

tarunuday gravatar image tarunuday  ( 2018-03-15 10:50:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-21 23:58:50 -0500

Seen: 2,594 times

Last updated: Feb 22 '16