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

Revision history [back]

click to hide/show revision 1
initial version

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

Essential, 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   }

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

Essential, 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   }