ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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.