Ask Your Question

tf broadcasting and listening in the same node

asked 2018-11-17 05:05:14 -0600

EunsanJo gravatar image

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();


        tf::StampedTransform(transform, tGetTime, "world", "test1"));

    tf::TransformListener listener;

    try {

      listener.waitForTransform("/test1", "/world", tGetTime,

      tf::StampedTransform transform;
      listener.lookupTransform("/test1", "/world", tGetTime, transform);


    } catch (tf::TransformException &ex) {

  return 0;

On top of that I've simplified the code to make it easier to understand.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-17 05:25:32 -0600

gvdhoorn gravatar image

I think this problem is "time"

that might be, but perhaps not in the way you think.

You create your TransformListener inside your while loop. Don't do that. It needs time to fill its buffer, and you don't give it any.

Create it right after your NodeHandle, and use an AsyncSpinner.

edit flag offensive delete link more


Thank you. You are the best. I succeeded because I put 'listener creator' outside 'while loop'!

EunsanJo gravatar image EunsanJo  ( 2018-11-17 05:46:08 -0600 )edit

Using an AsyncSpinner might still be a good thing to do, just to avoid blocking updates to your TransformListener with long running operations.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-17 06:01:49 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-11-17 05:05:14 -0600

Seen: 367 times

Last updated: Nov 17 '18