Ask Your Question
5

tf2 transformPose in C++

asked 2017-05-09 12:28:40 -0600

AndyZe gravatar image

updated 2017-05-09 12:47:33 -0600

I'm used to the transformPose() method and similar from tf. However, the tf listener was apparently missing some static poses so I switched to tf2. Now I can get the TransformStamped but I'm struggling to actually apply it to a pose. So, how do you apply a TransformStamped to a PoseStamped?

The tf2 tutorials don't seem to cover this crucial aspect. (they should) Apologies if there's an obvious answer that I missed.

The Python version of this question

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
6

answered 2017-05-10 13:42:10 -0600

AndyZe gravatar image

updated 2020-06-15 09:59:46 -0600

Thanks to @dhood's answer on this question, I dug through tf2_geometry_msgs and found doTransform(). I'll probably edit the tf2 tutorials to mention this. Here's the gist of getting a TransformStamped and applying it to a PoseStamped with tf2:

   #include <tf2_geometry_msgs/tf2_geometry_msgs.h>

   #include <tf2_ros/transform_listener.h>

. . .

tf2_ros::Buffer tf_buffer;
tf2_ros::TransformListener tf2_listener(tf_buffer);
geometry_msgs::TransformStamped base_link_to_leap_motion; // My frames are named "base_link" and "leap_motion"

base_link_to_leap_motion = tf_buffer.lookupTransform("leap_motion", "base_link", ros::Time(0), ros::Duration(1.0) );

tf2::doTransform(robot_pose, robot_pose, base_link_to_leap_motion); // robot_pose is the PoseStamped I want to transform
edit flag offensive delete link more

Comments

1

And a more in-depth tutorial.

AndyZe gravatar image AndyZe  ( 2017-05-11 15:32:29 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2017-05-09 12:28:40 -0600

Seen: 6,985 times

Last updated: Jun 15