0
$\begingroup$

Rosanswers logo

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!


Originally posted by edmond320 on ROS Answers with karma: 61 on 2016-02-22

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

hi!,

I think that the information you are looking for, is published in the topic /map. If you take a look to the gmapping documentation http://wiki.ros.org/gmapping , you will see that gmapping, publish the occupancy grid information, in the format of a message of the type http://docs.ros.org/api/nav_msgs/html/msg/OccupancyGrid.html, in the topic /map. So, you should just subscribe to that topic, to get the information you are looking for.

Hope this helps you!


Originally posted by donmrsir with karma: 363 on 2016-02-22

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by edmond320 on 2016-02-24:
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?

Comment by donmrsir on 2016-02-24:
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?

Comment by az on 2018-03-01:
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?

Comment by edmond320 on 2018-03-05:
@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.

Comment by az on 2018-03-10:
Thanks alot!

Comment by tarunuday on 2018-03-15:
Essentially, the grid data is in row-major index format - which means if the width of the row (which you can get from map.info.width) is 1000,

map.data[0] = [0,0]

map.data[356] = [356,0]

map.data[1000]= [0,1]

map.data[72653]=[653,72]

map.data[ i ]=[(i%width),(int)(i/width)]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.