lookupTransform is throwing error
I have a static transformation, which I am trying to fetch using lookupTransform
. However, it is not working and throwing following error-
"base" passed to lookupTransform argument target_frame does not exist.
Below is the code snippet-
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
try {
// get the latest available transformation
geometry_msgs::TransformStamped t = tfBuffer.lookupTransform("base", "kinect2_link", ros::Time(0));
}
catch (tf2::TransformException& ex) {
ROS_ERROR_STREAM("Unable to fetch static transformation. " << ex.what());
}
I tried to debug the issue. The transformation is available in rostopic. Please see below
ravi@lab:~/ros_ws$ rostopic echo /tf_static
transforms:
-
header:
seq: 0
stamp:
secs: 1522910703
nsecs: 637645959
frame_id: base
child_frame_id: kinect2_link
transform:
translation:
x: 0.824234432376
y: 0.100365580648
z: 0.140681429475
rotation:
x: -0.345864766717
y: 0.656658630544
z: -0.629654174274
w: 0.229592305828
A similar question was asked here but unfortunately, it doesn't contain any answer.
My question is how to get the static transformations from tf
using C++. I am using ROS Indigo on Ubuntu 14.04 LTS OS.
Unless we've run into a regression or undiscovered bug, this might be just a matter of not waiting long enough for the buffer to actually contain those transforms. See #q287540 for a possible duplicate.
I need to check the reference, you provided. However I have a question regarding wait time for buffer. I am trying to access static transformation, which is never going to change. Is the wait concept applies to this scenario as well?
I would have to verify that for static transforms. But in general instantiating a buffer and listener and then using them immediately is not going to work. The infrastructure needs some time to be able to gather all the information (essentially: receive TF msgs and process it).
Yes even static transform information must be propagated after the listener is created. It needs time to set up the communication channels and for the messages to be sent from all the sources.
@tfoote: I see. I am going to initialize the buffer with a wait time. But how do we decide this wait time? Too much wait is useless and too less doesn't work !
tf2_ros::Buffer
has a methodcanTransform(..)
that you can use to see whether the necessary information is present in the local buffer.