0
$\begingroup$

Rosanswers logo

We have successfully created a map and our robot localizes well using AMCL. Now we want to be able to get the coordinates of the robot once it has localized itself within the map that we supplied. What is the best way to get the coordinates of the robot relative to the map?

Thanks


Originally posted by zlalanne on ROS Answers with karma: 65 on 2012-04-14

Post score: 5

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

The best way to get the current location of the Turtlebot is using TF. Assuming you are in C++ and already have a tf::TransformListener object as listener, that your robot's local frame is base_link and your map frame is map, you could use a block of code like the following:

geometry_msgs::PoseStamped pBase, pMap;
pBase.header.frame_id = "base_link";
pBase.pose.position.x = 0.0;
pBase.pose.position.y = 0.0;
pBase.pose.orientation = tf::createQuaternionMsgFromYaw(0.0);
ros::Time current_transform = ros::Time::now();
listener.getLatestCommonTime(pBase.header.frame_id, "map", current_transform, NULL);
pBase.header.stamp = current_transform;
listener.transformPose("map", pBase, pMap);
// pMap now contains the pose of the robot transformed into map 
// coordinates according to the TF data available at time "current_transform"

If you are unfamiliar with the TF library, you should read through the tutorials.


Originally posted by Eric Perko with karma: 8406 on 2012-04-16

This answer was ACCEPTED on the original site

Post score: 7

$\endgroup$
0
$\begingroup$

Rosanswers logo

rosrun tf tf_echo /map /base_link


Originally posted by dornhege with karma: 31395 on 2012-04-14

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by zlalanne on 2012-04-15:
So this launches a node that publishes the data I need correct? Do I need to subscribe to a topic it publishes? Thanks for the help.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.