Created
June 3, 2016 20:25
-
-
Save wngreene/0bc1d59e5339c94541101897bab2493b to your computer and use it in GitHub Desktop.
Example of how to equery tf for a transform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In header: | |
#include <tf2_ros/transform_listener.h> | |
std::shared_ptr<tf2_ros::TransformListener> tf_listener_; | |
tf2_ros::Buffer tf_buffer_; | |
// In constructor: | |
tf_listener_ = | |
std::make_shared<tf2_ros::TransformListener>(tf_buffer_); | |
// ... | |
// Get pose of camera. | |
geometry_msgs::TransformStamped tf; | |
try { | |
// Need to remove leading "/" if it exists. | |
std::string rgb_frame_id = rgb->header.frame_id; | |
if (rgb_frame_id[0] == '/') { | |
rgb_frame_id = rgb_frame_id.substr(1, rgb_frame_id.size()-1); | |
} | |
tf = tf_buffer_.lookupTransform(world_frame_id_, rgb_frame_id, | |
ros::Time(rgb->header.stamp), | |
ros::Duration(1.0/15)); | |
} catch (tf2::TransformException &ex) { | |
ROS_ERROR("%s", ex.what()); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment