I have not tried this yet but this is what I would do:
geometry_msgs::PointStamped initial_pt;
ros::Publisher odom_pub = node.advertise<geometry_msgs::vector3>("/visualization_marker", 1);
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
ros::Rate rate(10.0);
while (node.ok()){
geometry_msgs::TransformStamped transformStamped;
try{
transformStamped = tfBuffer.lookupTransform("/base_2", "/base_1", ros::Time(0));
geometry_msgs::PointStamped transformed_pt ;
tf2_geometry_msgs::do_transform(initial_pt, transformed_pt, transformStamped);
geometry_msgs::vector3 v;
v.x = transformed_pt.point.x;
v.y = transformed_pt.point.y;
v.z = transformed_pt.point.z;
odom_pub.publish(v);
}
catch (tf2::TransformException &ex) {
ROS_WARN("%s",ex.what());
ros::Duration(1.0).sleep();
continue;
}
from http://docs.ros.org/diamondback/api/tf2_geometry_msgs/html/namespacetf2.html
or extracting a snippet from http://wiki.ros.org/tf2/Tutorials/Using%20stamped%20datatypes%20with%20tf2%3A%3AMessageFilter
geometry_msgs::PointStamped initial_pt;
ros::Publisher odom_pub = node.advertise<geometry_msgs::vector3>("/visualization_marker", 1);
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
ros::Rate rate(10.0);
initial_pt.header.frame_id = "/base1";
while (node.ok()){
try
{
tbuffer_.transform(initial_pt, transformed_pt, "/base2");
geometry_msgs::vector3 v;
v.x = transformed_pt.point.x;
v.y = transformed_pt.point.y;
v.z = transformed_pt.point.z;
odom_pub.publish(v);
}
catch (tf2::TransformException &ex)
{
ROS_WARN("Failure %s\n", ex.what()); //Print exception which was caught
continue;
}
}
Originally posted by borgcons with karma: 176 on 2017-10-17
This answer was ACCEPTED on the original site
Post score: 2