Ask Your Question

Revision history [back]

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.