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

Where am I in the map?

asked 2011-06-15 04:01:00 -0600

koloman gravatar image

updated 2014-01-28 17:09:51 -0600

ngrennan gravatar image

How do I get the occupancy value from the map at my robots position? The map is increasing dynamically as my robot moves around, right? Hence the (0,0) index of the data array may shift as my map expands. What I want is the occupancy value at the very position of my robot. How can I achieve this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
9

answered 2011-06-15 04:39:51 -0600

Brian Gerkey gravatar image

updated 2011-06-20 04:40:35 -0600

To know where the robot is in the map, you want to transform the origin of the base_link frame into the map frame.

In addition to the map, SLAM systems (gmapping and karto) publish transform data. In particular, they provide the transform from the map frame to the odom frame. Another node (which one will depend on what kind of robot you're using) should already be publishing the transform from the odom frame to the base_link frame.

The tf library will chain those transforms together for you. The details will depend on whether you're writing in C++ or Python; check the tf documentation. As an example, from the command-line, you can do this while the SLAM system is running:

rosrun tf tf_echo map base_link

Note: frames names are configurable, and your system may use different names from the ones I gave above. But the semantics of them is the same.

Given the robot's pose in the map frame, if you want the corresponding index into the occupancy grid map, you'd do something like this:

grid_x = (unsigned int)((map_x - map.info.origin.position.x) / map.info.resolution)
grid_y = (unsigned int)((map_y - map.info.origin.position.y) / map.info.resolution)

In principle, you should also account for the orientation of the origin (map.info.origin.orientation), but in practice there's no rotation.

edit flag offensive delete link more

Comments

Allright. So all I have to do is transform the base_link into the map frame. Further I just take the pose, devide the coordinate components by the map resolution and there I have the correct indices for the map data array? what if they are negative? shouldn't I somehow account for the map origin?
koloman gravatar image koloman  ( 2011-06-17 03:18:07 -0600 )edit
I updated the answer with some code for that pose-to-grid conversion.
Brian Gerkey gravatar image Brian Gerkey  ( 2011-06-20 04:41:02 -0600 )edit

Are these coordinates grid_x and grid_y in the /map frame. I have an object with its location static w.r.t the /map frame. So as the map changes dynamically (so does the location of object but static w.r.t map), will these coordinates also remain static?

Kushaagra gravatar image Kushaagra  ( 2015-06-08 19:05:41 -0600 )edit

Where do map_x and map_y come from? From map or from base_link? How can I get map_x or map_y what should I "calculate"?

Michdo93 gravatar image Michdo93  ( 2019-01-17 09:10:46 -0600 )edit

Question Tools

5 followers

Stats

Asked: 2011-06-15 04:01:00 -0600

Seen: 7,270 times

Last updated: Jan 28 '14