Ask Your Question
3

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
6

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 ( 2011-06-17 03:18:07 -0600 )edit
I updated the answer with some code for that pose-to-grid conversion. Brian Gerkey ( 2011-06-20 04:41:02 -0600 )edit

Your Answer

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

Add Answer

[hide preview]

Question Tools

Follow
3 followers

Stats

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

Seen: 747 times

Last updated: Jun 20 '11