Ask Your Question

Revision history [back]

Hi Parth2851,

As you mentioned, the map message consists on a 1D array containing all the information.

If you want to convert this to a 2D matrix, you can extract the positions using the map info metadata, where the height, width and resolution of the map are provided.

A simple function to extract a given position (in pixels) of the map, can be like this

    int getMapValue(int height, int width, const nav_msgs::OccupancyGrid& map)
{
    int position = map.info.width * height + width;        // Finds the position in the data vector.
    return map.data[position];                  // Gets the value from the position
}

if you want to extract a position on meters, then you should take into account the resolution of the map, also available on the map info message.

Regards,