Rosanswers logo

Looking through the documentation of costmap_2d::Costmap2D Class Reference I am seeing that a lot of the functionality for querying specific values about cells uses unsigned ints. For example;

getCost (unsigned int mx, unsigned int my) const Get the cost of a cell in the costmap.

getIndex (unsigned int mx, unsigned int my) const Given two map coordinates... compute the associated index.

indexToCells (unsigned int index, unsigned int &mx, unsigned int &my) const Given an index... compute the associated map coordinates."

My question is why does it not use floats instead of unsigned ints? Because if I want to get the cost of a cell at map coordinate (25.25, 13.75), and the resolution is small, then the integer value (25, 14) will not be able to query the value of the true cell I want.

This may be a pretty bad question cause I am so new to this, but it has really been frustrating my understating and use of the ROS costmap2D.

Thanks ahead of time!


Originally posted by JackB on ROS Answers with karma: 977 on 2019-03-29

Post score: 0

Original comments

Comment by gvdhoorn on 2019-03-29:
I would say because a costmap is a discretised representation of a 2d area, and that discretisation was done at a certain resolution.

Given a certain resolution, it doesn't make sense to ask for a value at .25 and .75 of a cell, as there can be no more accurate data than the resolution allows.

If you're asking why you can't use "real coordinates" (ie: meters from the origin" or something similar") that would be something else.

Comment by JackB on 2019-03-29:
I think that might be what I am really trying to understand, why can you not use meters from origin to work with the costmap.

Comment by ahendrix on 2019-04-01:
The Costmap2D::worldToMap function converts world coordinates (in meters, as doubles) to map coordinates that you can use with the other functions. Perhaps that's what you're looking for?


1 Answer 1


Rosanswers logo

The costmap is internally stored as a one-dimensional array. Thus, for looking up data, you use the array index or the cell coordinates mx and my.

If you want to use metric coordinates, you need to first retrieve the respective cell coordinates using one of the worldToMap functions (inverse is mapToWorld). Those functions take care of converting metric to cell (or map) coordinates (and vice versa) observing the respective sizes in x and y as well as the resolution.

Originally posted by mgruhler with karma: 12390 on 2019-04-01

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.