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

koloman's profile - activity

2022-05-06 08:34:06 -0500 received badge  Stellar Question (source)
2014-01-18 09:12:46 -0500 received badge  Favorite Question (source)
2012-11-05 07:12:29 -0500 received badge  Famous Question (source)
2012-11-05 07:12:29 -0500 received badge  Notable Question (source)
2012-06-14 20:19:39 -0500 received badge  Popular Question (source)
2012-02-13 00:04:04 -0500 received badge  Good Question (source)
2012-01-10 16:20:03 -0500 received badge  Nice Question (source)
2011-06-20 05:03:56 -0500 received badge  Supporter (source)
2011-06-20 05:03:49 -0500 received badge  Scholar (source)
2011-06-17 10:50:08 -0500 marked best answer Where am I in the map?

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.

2011-06-17 03:18:07 -0500 commented answer Where am I in the map?
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?
2011-06-15 08:00:45 -0500 received badge  Student (source)
2011-06-15 04:03:37 -0500 received badge  Editor (source)
2011-06-15 04:01:00 -0500 asked a question Where am I in the map?

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?