TF listening fails when called from a specific class
Hi all,
I initially had one C++ class broadcasting and listening to tf:Transforms successfuly. The structure of my class was something like:
class TF_Listening_OK {
private:
tf::TransformBroadcaster _transf_bdcst;
tf::TransformListener _transf_lsten;
public:
void spin() {
Rate r(25);
while(ros::ok()) {
tf::Transform transform = blablabla...;
_transf_bdcst.sendTransform(tf::StampedTransform(transform,
Time::now(),
"world",
"myframe"));
ros::spinOnce();
}
}
void someCallback() {
try {
PoseStamped pstdin, pstdout;
pstdin.header.frame_id = "world";
pstdin.pose = some_pose_in_world;
_transf_lsten.transformPose("myframe", pstdin, pstdout);
}
catch() we don't care...
}
The code hereabove works great! My issue comes in the next step.
Then I've created a TF_Listening_Failure class which does not broadcast any frame but which listen to some tf broadcasted by TF_Listening_OK. It's code is in the same node and same thread and is executed when a callback is received. Something like:
class TF_Listening_Failure {
private:
tf::TransformListener _transf_lsten;
public:
void someCallback() {
try {
PoseStamped pstdin, pstdout;
pstdin.header.frame_id = "myframe";
pstdin.pose = some_pose_in_myframe;
_transf_lsten.transformPose("world", pstdin, pstdout);
}
catch() we don't care...
}
But it fails with code:
terminate called after throwing an instance of 'tf::LookupException'
what(): Frame id /myframe does not exist! Frames (1):
Aborted (core dumped)
I am 400% sure that "myframe" is actually broadcasted with respect to "world". I can draw the tf tree seeing myframe published as a child of world at 25Hz. Not only the world frame does exist (I've also replaced world by other frames in the transformPose but it always fails) but also it's not even able to list available frames (= this aborted error, I figured out with gdb that it occured during spinOnce()).
The awful solution I've found for the moment is creating a PoseStamped TF_Listening_OK::performTFListening(PoseStamped pstdin)
. Calling this method from TF_Listening_Failure works well but this is SO UGLY.
I'm not sure whether the portion of code I've posted is useful, but I'm so lost with this issue that I don't know what is relevant. Any idea of what could be wrong? Can we have only one declared tf listener of something like this? Thank you by advance for your help.