tf broadcasting and listening in the same node
I am currently trying to make a perception part using tf.
My robot 's position is broadcasted to tf, and the robot tries to read obstacles using tf. I want to put this on the same node " " test1 "passed to lookupTransform argument target_frame does not exist. "Message is generated.
What happens when two nodes tf each succeed, and one node should not?
I think this problem is "time" and I have put in various times. ros :: Time (), ros :: Time (0). ros :: Time :: now (), ros :: Time :: now () - ros :: Duration (0.1) etc ..
But it was not all.
I tested with two threads on one node, which was a success. What is the problem?
#include "tf/transform_listener.h"
#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
int main(int argc, char **argv) {
ros::init(argc, argv, "tf_b");
tf::TransformBroadcaster br;
tf::Transform transform;
tf::Quaternion q;
ros::NodeHandle nh;
transform.setOrigin(tf::Vector3(1.0, 1.0, 1.0));
q.setRPY(0, 0, 0);
ros::Rate loop_rate(10);
while (ros::ok()) {
ros::Time tGetTime = ros::Time::now();
transform.setRotation(q);
br.sendTransform(
tf::StampedTransform(transform, tGetTime, "world", "test1"));
tf::TransformListener listener;
try {
listener.waitForTransform("/test1", "/world", tGetTime,
ros::Duration(0.1));
tf::StampedTransform transform;
listener.lookupTransform("/test1", "/world", tGetTime, transform);
ROS_INFO_STREAM(transform.getOrigin().getX());
} catch (tf::TransformException &ex) {
ROS_ERROR(ex.what());
}
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
On top of that I've simplified the code to make it easier to understand.