ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Writing a tf broadcaster (Python)

asked 2021-05-12 01:09:18 -0500

Chan gravatar image

updated 2021-05-12 02:27:55 -0500

I don't really understand this tutorial. Link to the tutorial :- Click here

I can understand how broadcaster code works but the launch code seems too strange.

    <node name="turtle1_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
  <param name="turtle" type="string" value="turtle1" />
</node>
<node name="turtle2_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
  <param name="turtle" type="string" value="turtle2" /> 
</node>

To my understanding, the above code creates two instances of the node right? So we should have turtle1 and turtle2 right?

But they mentioned,

"If you run tf_echo for the transform between the world and turtle 2, you should not see a transform, because the second turtle is not there yet."

I really don't understand how this works. Please explain.

edit retag flag offensive close merge delete

Comments

What tutorial? Can you please update your question to a link to the tutorial?

jayess gravatar image jayess  ( 2021-05-12 01:52:50 -0500 )edit
1

Updated the question with link. Thanks.

Chan gravatar image Chan  ( 2021-05-12 02:28:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-12 03:28:16 -0500

updated 2021-05-12 03:46:07 -0500

The above code creates 2 instances of the turtle_tf_brodcaster.py node.

By running rosnode list, you would find the two nodes, named as turtle1_tf_broadcaster and turtle2_tf_broadcaster respectively.

We are pasing the values of the param named turtle to the two nodes. For the first node, we are setting the value of the turtle param to turtle1, and for the second node, we are setting it to turtle2.

Each node is responsible for finding the value of world -> turtleX transform and then printing it.

world -> turtle1 transform exists because of the following lines present in the launch file -

<node pkg="turtlesim" type="turtlesim_node" name="sim"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>

That's why, world -> turtle1 transform would be printed by the turtle1_tf_brodcaster node.

world -> turtle2 transform is not being being published on the tf tree at the moment. You can run another instance of turtlesim_node so that world -> turtle2 transform starts getting published. Once you do that, turtle2_tf_brodcaster node would be able to print the same.

Does that make sense?

edit flag offensive delete link more

Comments

1

Great explanation. I tried another one. I removed one instance and kept that param name as turtle2. When I viewed the tf tree, there is no tf data published. Only if I keep the param name as turtle1, it's working. Why is that happening?

Chan gravatar image Chan  ( 2021-05-12 03:33:43 -0500 )edit

<node pkg="turtlesim" type="turtlesim_node" name="sim"/> is responsible for generating the world -> turtle1 transform.

If you run turtle_tf_brodcaster node with the turtleparam set to turtle2, it won't work because it would try to find the transform between world -> turtle2 and then publish it. But, the turtlesim_node is publishing world -> turtle1 transform on the tf tree.

skpro19 gravatar image skpro19  ( 2021-05-12 03:42:27 -0500 )edit

Delete everything from the launch file and just keep this -

<node pkg="turtlesim" type="turtlesim_node" name="sim"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>

Now, visualise the tf tree.

skpro19 gravatar image skpro19  ( 2021-05-12 03:43:41 -0500 )edit

Oh cool. Still I don't understand few things. If turtlesim is publishing the world to turtle1 transform, what is the broadcaster code given in the tutorial used for? Isn't it the reason to publish a transform? Am I confusing myself?

Chan gravatar image Chan  ( 2021-05-12 03:52:40 -0500 )edit

Could you please attach the tf tree you see when you just keep this in your launch file -

<node pkg="turtlesim" type="turtlesim_node" name="sim"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>
skpro19 gravatar image skpro19  ( 2021-05-12 03:54:32 -0500 )edit

Sorry for the late reply. I'm getting as "no tf data received" for those two lines.

Chan gravatar image Chan  ( 2021-05-12 23:02:18 -0500 )edit
2

turtlesim_node only publishes the turtle's pose to a topic--not an actual transform. When you run the launch file, turtlesim_node spawns one turtle automatically (use the spawn service to make more) and publishes the pose for turtle1 (default name in the source code) on the /turtle1/pose topic. The turtle1_tf_broadcaster node subscribes to that topic, gets the pose, and publishes the corresponding transform to the tf tree.

Until you spawn a second turtle, turtlesim_node doesn't publish on the /turtle2/pose topic, so the second broadcaster won't get a pose and won't publish the transform for turtle2. Therefore, the transform won't exist in the tf tree.

tryan gravatar image tryan  ( 2021-05-12 23:39:48 -0500 )edit
1

That explains all. Thanks a lot both..!

Chan gravatar image Chan  ( 2021-05-13 00:00:35 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-05-12 01:09:18 -0500

Seen: 245 times

Last updated: May 12 '21