Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 tfBuffer;
tf2_ros::TransformListener tf2_listener(tfBuffer);
geometry_msgs::TransformStamped base_link_to_leap_motion; // My frames are named "base_link" and "leap_motion"

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

tf2::doTransform(robotPose, robotPose, base_link_to_leap_motion); // robotPose is a PoseStamped

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 tfBuffer;
tf2_ros::TransformListener tf2_listener(tfBuffer);
geometry_msgs::TransformStamped base_link_to_leap_motion; // My frames are named "base_link" and "leap_motion"

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

tf2::doTransform(robotPose, robotPose, base_link_to_leap_motion); // robotPose is a PoseStamped
the PoseStamped I want to transform

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 tfBuffer;
tf2_ros::TransformListener tf2_listener(tfBuffer);
geometry_msgs::TransformStamped base_link_to_leap_motion; // My frames are named "base_link" and "leap_motion"

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

tf2::doTransform(robotPose, robotPose, base_link_to_leap_motion); // robotPose is the PoseStamped I want to transform