TF2 lookupTransform problem in Qt5
When I was writing a Qt5 widget use tf2, I got all zero when print Translation and Rotation.
I reviewed some similar questions and modified my program, it was written inside the UI's constructor, just like this:
tf2_ros::TransformListener tfListener(tfBuffer, nh_);
connect(ui->testButton, SIGNAL(clicked()), this, SLOT(testTf2()));
try{
if(tfBuffer.canTransform("map", "base_link", ros::Time::now(), ros::Duration(1)))
ts = tfBuffer.lookupTransform("map", "base_link", ros::Time::now(), ros::Duration(0));
} catch (tf2::TransformException &ex) {
ROS_WARN("%s", ex.what());
}
And in testTf2(), I print ts.
qDebug() << ts.transform.translation.x;
qDebug() << ts.transform.rotation.w;
etc.
I had set the target_time
and time_out
param, and in case, add a canTransform func, but still got 0
.
With rosrun tf tf_echo map base_link
print:
- Translation: [-0.478, 0.148, 0.017]
- Rotation: in Quaternion [0.000, 0.000, -0.802, 0.597]
in RPY (radian) [0.000, 0.000, -1.862]
in RPY (degree) [0.000, 0.000, -106.708]
I also run rosrun tf2_tools view_frames.py
, it seems good.
I want to know if my method is wrong, or the parameters set are wrong?