Tf to tf2 upgrade adaptation problem
Hello everyone,
I wanna update tf to tf2 in my code, but get some question about it.
There are tf
part :
tf::TransformListener listener;
tf::StampedTransform transform;
try
{
listener.waitForTransform("/map", "/base_link", ros::Time::now(), ros::Duration(2));
listener.lookupTransform("/map", "/base_link", ros::Time(0), transform);
}
catch(tf::TransformException ex)
{
ROS_ERROR("%s", ex.what());
ros::Duration(1.0).sleep();
QMessageBox::information(this, "Error", QString::fromStdString(ex.what()));
return ;
}
geometry_msgs::Transform tt;
tf::transformTFToMsg(transform, tt);
pose.position.x = tt.translation.x;
pose.position.y = tt.translation.y;
pose.position.z = tt.translation.z;
pose.orientation.x = tt.rotation.x;
pose.orientation.y = tt.rotation.y;
pose.orientation.z = tt.rotation.z;
pose.orientation.w = tt.rotation.w;
pose
is a parameter, via geometry_msgs::Pose &pose
When I follow the doc to update to tf2, I get some wrong.
There are tf2 part:
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
geometry_msgs::TransformStamped transformStamped;
try
{
transformStamped = tfBuffer.lookupTransform("/map", "/base_link", ros::Time(0));
}
catch (tf2::TransformException &ex){
ROS_WARN("%s", ex.what());
ros::Duration(1.0).sleep();
}
geometry_msgs::Transform tt;
tf::transformTFToMsg(transformStamped, tt);
I Don't know how to transfrom data under tf2, and I didn‘t find the relevant function in doc.
I want to know how to modify my code to achieve the same result?
Is there a function just like transformTFToMsg
I can replace?