ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange

# Confusion regarding mx, my variables in costmap_2d::worldToMap method

The worldToMap function is defined as follows in the official documentation - worldToMap (double wx, double wy, unsigned int &mx, unsigned int &my) const.

What are the variables mx and my? I am not sure but wx and wy represent the points that we want to transform to the map frame.

edit retag close merge delete

Sort by » oldest newest most voted

From the documentation:

Parameters:
wx - The x world coordinate
wy - The y world coordinate
mx - Will be set to the associated map x coordinate
my - Will be set to the associated map y coordinate

Essentially, the world coordinates are in meters and the map coordinates are in pixels. This function doesn't transform between frames in the tf tree; it converts physical coordinates (e.g., [meters] in the map frame) into image coordinates in the current costmap image, using an origin shift and scaling by the costmap resolution. Here's the function implementation for clarity:

00548   bool Costmap2D::worldToMap(double wx, double wy, unsigned int& mx, unsigned int& my) const {
00549     if(wx < origin_x_ || wy < origin_y_)
00550       return false;
00551
00552     mx = (int) ((wx - origin_x_) / resolution_);
00553     my = (int) ((wy - origin_y_) / resolution_);
00554
00555     if(mx < size_x_ && my < size_y_)
00556       return true;
00557
00558     return false;
00559   }
more

1

Thank you.

( 2021-01-11 12:08:12 -0600 )edit