ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you just want to have the pose of the robot in map, all you need to do is look up the transform between /map and your base frame. There is no need to subscribe to the odom topic for that.
There are quite a few issues in your code. You are creating the TransformListener and a publisher object whenever the callback is invoked. This probably won't have the desired effect. The transform listener needs a while to build up the complete tf tree. Aren't you getting transform exceptions? You should have only one TransformListener instance that is created right after ros::init and stays valid until the end of the program. You also shouldn't create and destroy publisher objects frequently in a callback because this creates a lot of traffic to the ros core and not all subscribers might be registered already when you call the publish method. I also don't understand why you have a rate.sleep in your code.
2 | No.2 Revision |
If you just want to have the pose of the robot in map, all you need to do is look up the transform between /map and your base frame. There is no need to subscribe to the odom topic for that.that. The code for getting the pose of base_footprint in map would be:
tf::StampedTransform transform_in_map;
try {
listener.lookupTransform("map", "base_footprint", ros::Time(0), transform_in_map);
} catch(tf::TransformException &exception) {
ROS_ERROR("%s", exception.what());
}
There Most tools, e.g. rviz, are quite a few issues in your code. You are creating using this mechanism to calculate the TransformListener and a publisher object whenever robot pose with respect to map instead of directly subscribing to odom. I think the callback only node that really uses the odom topic on the pr2 is invoked. This probably won't have the desired effect. The transform listener move_base node because it needs a while to build up the complete tf tree. Aren't you getting transform exceptions? You should have only one TransformListener instance that is created right after ros::init and stays valid until the end of the program. You also shouldn't create and destroy publisher objects frequently in a callback because this creates a lot of traffic to the ros core and not all subscribers might be registered already when you call the publish method. I also don't understand why you have a rate.sleep in your code.current velocity. Everything else uses tf.