Ask Your Question
0

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

asked 2021-01-11 09:56:11 -0500

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-01-11 11:11:15 -0500

tryan gravatar image

updated 2021-01-11 11:30:15 -0500

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   }
edit flag offensive delete link more

Comments

1

Thank you.

skpro19 gravatar image skpro19  ( 2021-01-11 12:08:12 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-01-11 09:56:11 -0500

Seen: 71 times

Last updated: Jan 11