# The meaning of manually written "multiple\_broadcaster.py"

**URL:** <https://get-help.theconstruct.ai/t/the-meaning-of-manually-written-multiple-broadcaster-py/19838>\
**Category:** TF ROS 101\
**Created:** [October 11, 2022, 9:20am UTC](https://get-help.theconstruct.ai/t/the-meaning-of-manually-written-multiple-broadcaster-py/19838 "2022-10-11T09:20:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MeineLiebeAxt](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/m/45deac/32.png) [@MeineLiebeAxt](https://get-help.theconstruct.ai/u/MeineLiebeAxt)\
**Post date:** [October 11, 2022, 9:20am UTC](https://get-help.theconstruct.ai/t/the-meaning-of-manually-written-multiple-broadcaster-py/19838/1 "2022-10-11T09:20:10Z")

</div>

Hi,  
I am doing “3 Publisch & Subscribe to TF data” of “TF” course. In this case we are learning how to write a py-file to broadcast/publish TF data. But I find that even though without this manually written py-file, we can still see turtle1 and turtle2 in rqt\_tf\_tree and rviz.  
If we add “coke\_can” in name\_list in this py-file, rqt\_tf\_tree will add “coke\_can” as well. But why “turtle1” and “turtle2” always show themselves? Where has this defined? Even though I set the name\_list in “multiple\_broadcaster.py” just as [“coke\_can”], “turtle1” and “turtle2” remain. As a result, what is the meaning of this manually written “multiple\_broadcaster.py”? Just add ‘‘other’’ objects to present?

The manually written “multiple\_broadcaster.py” is here:

```auto
#! /usr/bin/env python
import rospy
import time
import tf
from turtle_tf_3d.get_model_gazebo_pose import GazeboModel

class MultiTfBroadcast(object):

```

```
def __init__ (self, robot_name_list, loop_rate=5.0):

    self._robot_name_list = robot_name_list
    self._gazebo_model_object = GazeboModel(self._robot_name_list)

    # hz
    self._rate = rospy.Rate(loop_rate)

    # We start the Tf broadcaster
    self._broad_caster_tf = tf.TransformBroadcaster()

    # Leave enough time to be sure the Gazebo Model logs have finished
    time.sleep(1)
    rospy.loginfo("Ready..Starting to Publish TF data now...")

def handle_turtle_pose(self, pose_msg, robot_name, reference_frame_data="/world"):

    self._broad_caster_tf.sendTransform((pose_msg.position.x, pose_msg.position.y, pose_msg.position.z),
                                        (pose_msg.orientation.x, pose_msg.orientation.y,
                                         pose_msg.orientation.z, pose_msg.orientation.w),
                                        rospy.Time.now(),
                                        robot_name,
                                        reference_frame_data)

def start_loop(self):

    while not rospy.is_shutdown():
        for robot_name in self._robot_name_list:
            pose_now = self._gazebo_model_object.get_model_pose(robot_name)
            if not pose_now:
                robot_name_msg = "The " + \
                    str(robot_name) + \
                    "'s Pose is not yet available...Please try again later"
                rospy.loginfo(robot_name_msg)
            else:
                self.handle_turtle_pose(pose_now, robot_name)
        self._rate.sleep()

```

def main():

```
rospy.init_node('publisher_of_tf_node', anonymous=True)
multi_tf_broadcast_obj = MultiTfBroadcast(
    robot_name_list=["turtle1", "turtle2", "coke_can"])

try:
    multi_tf_broadcast_obj.start_loop()
except rospy.ROSInterruptException:
    pass

```

if **name** == ‘ **main** ’:  
main()

---

<div class="post-metadata">

**Author:** ![rzegers](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rzegers/32/7010_2.png) [@rzegers](https://get-help.theconstruct.ai/u/rzegers)\
**Post date:** [October 12, 2022, 8:30am UTC](https://get-help.theconstruct.ai/t/the-meaning-of-manually-written-multiple-broadcaster-py/19838/2 "2022-10-12T08:30:32Z")

</div>

Hello @MeineLiebeAxt,

as I understand from you post you are executing the multiple\_broadcaster.py script after having modified this line here:

```auto
multi_tf_broadcast_obj = MultiTfBroadcast(
    robot_name_list=["turtle1", "turtle2"])

```

into this:

```auto
multi_tf_broadcast_obj = MultiTfBroadcast(
    robot_name_list=["coke_can"])

```

and you are wondering why in the new version of your multiple\_broadcaster.py file the TF’s for turtle1 and turtle2 are also being published. Did I understand your question correctly?

The answer is they should not be published. So something else must be causing this issue.

To start, please confirm a few things:

- You have saved your new `multiple_broadcaster.py` script and the line above is like so:

```auto
multi_tf_broadcast_obj = MultiTfBroadcast(
    robot_name_list=["coke_can"])

```

- You have stopped all ROS nodes running in every Webshell before you run you new code. To do so switch to every Webshell and press Ctrl + C.

- Confirm that when you execute the script you see these lines printed out to the console:

```auto
user:~/catkin_ws/src/tf_exercises_pkg$ rosrun tf_exercises_pkg multiple_broadcaster.py
[INFO] [1665562839.223504, 0.000000]: Retrieveing Model indexes
[INFO] [1665562839.256574, 481.781000]: Final robots_index_dict = {'coke_can': 1}
[INFO] [1665562840.266317, 482.797000]: Ready..Starting to Publish TF data now...

```

The second INFO log shows the name of the objects who’s TF’s will be broadcasted in lines above it is just `coke_can`. In that case you should only see the TF for `coke_can` being published.

Hope this helps,

Roberto

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/6966_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [October 17, 2022, 7:00am UTC](https://get-help.theconstruct.ai/t/the-meaning-of-manually-written-multiple-broadcaster-py/19838/3 "2022-10-17T07:00:45Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
