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 -0600

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
1

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

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 imageedmond320 ( 2016-02-24 06:37:16 -0600 )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 imagedonmrsir ( 2016-02-24 08:40:46 -0600 )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 imageaz ( 2018-03-01 03:13:12 -0600 )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 imageedmond320 ( 2018-03-05 21:45:39 -0600 )edit

Thanks alot!

az gravatar imageaz ( 2018-03-10 15:14:12 -0600 )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 imagetarunuday ( 2018-03-15 10:50:18 -0600 )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

Stats

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

Seen: 1,783 times

Last updated: Feb 22 '16