# Why does costmap_2d::Costmap2D Class Reference use integers and not float?

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.

JJB

edit retag close merge delete

3

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.

( 2019-03-29 10:02:28 -0500 )edit

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.

( 2019-03-29 10:45:14 -0500 )edit
2

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?

( 2019-04-01 02:21:15 -0500 )edit

Sort by ยป oldest newest most voted

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.

more