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

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
2

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

donmrsir gravatar image

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!

edit flag offensive delete link more

Comments

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
1

@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
1

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

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

Question Tools

1 follower

Stats

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

Seen: 3,143 times

Last updated: Feb 22 '16