# Getting deeper into map (Occupancy Grid)

I'm developing a navigation algorithm, for which I need to find out corners and walls present in the room. I've been playing around with turtlebot simulation. I've made a very simple rectangular room of about 3.0 x 2.4 meter square. I've saved the map I generated using gmapping.

To find the corners and walls, I'm writing my own python script, using OpenCV functions like Harris Corner detection and Contours, and Canny. I'll be feeding the map.pgm file to do the same. I'll receive the pixels with corners and wall.

Now, I need to know where these are in relation to the bot. That's where the problem is.

I am not able to understand where does the map set its origin?

And if it's the same for every map file?

Does the robot's start, end pose or trajectory during the gmapping affect the map origin?

Also, if the map isn't at the top left corner, then how can I compute the distance between that pixel and my robot? I'd thought of identifying the pixel, then knowing its location with respect to map, and map's origin with respect to base_footprint. That way I'd know the vector joining the pixel and the base_footprint, and can drive to the point if I want to. I'm using the default 0.05 resolution, therefore each pixel should be 5 cm.

According to my observations, the map origin depends on the start pose of the robot while the mapping process. But if someone experienced can answer these questions, it would be a great help.

Also, if you think this isn't a good approach, and have a better approach, please teach me, or let me know. Thanks!

As per following images, map origin isn't same, and not necessarily at the top left. Map 1:

Map 2:

edit retag close merge delete

I read about nav_msgs/OccupancyGrid and nav_msgs/MapMetaData. So the /map will have cell values (-1, 0 or 100) and that MapMetaData is a part of OccupancyGrid message, and holds info like height, width, resolution and origin. Can I use the origin data to calculate the cell value of the map origin, and therefore to calculate its distance from any pixel of interest?

( 2019-11-09 05:53:26 -0600 )edit

Sort by » oldest newest most voted

Hi parzival,

I am not able to understand where does the map set its origin?

The origin of the map is defined in its .yaml file, its value depends on how it's created, but it usually when using gmapping it is given by the width and height of the map and its resolution, so as to try to put the 0,0 position at the center of the map. Although this is by no means a rule, it depends on a variety of things.

And if it's the same for every map file?

No, it depends on the map, moreover, it can be changed on the .yaml file

Does the robot's start, end pose or trajectory during the gmapping affect the map origin?

Not really, it only affects the position of the robot on the map

Also, if the map isn't at the top left corner, then how can I compute the distance between that pixel and my robot?

You need to put both things on the same reference frame, you can extract the position of a given pixel on the /map reference using a simple computation, an example can be

void mapToWorld(unsigned int map_x, unsigned int map_y, double& pos_x, double& pos_y, nav_msgs::OccupancyGrid map)
{
pos_x = map.info.origin.position.x + (map_x + 0.5) * map.info.resolution;
pos_y = map.info.origin.position.y + (map_y + 0.5) * map.info.resolution;
}


Then you can easily get the distance to the robot's position on the map.

more