Understanding Static Transforms Exercise 4.1

Hello,

In unit 5 exercise 4.1 in the launch file pub_static_transform.launch

<launch>
    <node pkg="tf" type="static_transform_publisher" name="node_static_tranform_box_bot_1_to_box_bot_2" 
          args="0 0 0 0 0 0 box_bot_1/odom box_bot_2/odom 100">
    </node>

    <node pkg="tf" type="static_transform_publisher" name="node_static_tranform_box_bot_2_to_box_bot_3" 
          args="0 0 0 0 0 0 box_bot_2/odom box_bot_3/odom 100">
    </node>

    <!-- Show in Rviz   -->
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find tf_static_transform)/rviz/base.rviz"/>


</launch>

i dont understand how do we decide the node names ?

and why i cant find the static_transform_publisher file in the tf package?

1 Like

Hello @erdemersan,

you can choose any node name of your preference when launching a node.
You could for instance name your nodes: “node1”, “node2”, “node3”, etc… But is this a good practice? I would say no. Remember that the node names are used when you run a command like rosnode list and they also display on your rqt_graph. Therefore in order to work efficiently with those tools I think that the name of a node should at least tell you what the node does. If you have many instances of the same node running it should also tell you why it is different to other nodes that have the same functionality.
In the example above the name “node_static_tranform_box_bot_1_to_box_bot_2” is telling you what it does: it is a static trnasform publisher node and it also tells you what is different in on node compared to the other one, which is: on node is a transform from bot_1_to_box_bot_2 and the other node is a transform from bot_2_to_box_bot_3. Can you see why these names where choosen?
Other alternative for these node names that I think are equally good are:

  • static_tf_bb1_to_bb2
  • static_tf_bb1_to_bb2
    they contain the same information however a little bit more criptical.

the bottom line is that you can always choose the name that you prefer.

That being said, when following the academy courses I it is highly recommended to follow the names that apear on the exercises, because we could be referencing a node by that names later in the course and I would be difficult to follow along I you decided to use a different name.

I hope this helps,

Roberto

Hello @erdemersan,

what do you mean by:

Please specify the the context and also what command or file are you running. Are you getting an error message? What is the expected output?

This will help us to understand your problem better.

Thanks,

Roberto

Thank you very much for the detailed answer.

According the previous courses i thought the name of the node was decided in the python script. For example in the script below;

#! /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"])

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


if __name__ == '__main__':
    main()

the name of the node was given as " publisher_of_tf_node " in the main function.

As i understand from your answer, i dont have to use the name " publisher_of_tf_node " in the launch file, if i specify a different node name then i will have a node as same functions but with a different name. For example;

<node pkg="tf_exercises_pkg" type=" multiple_broadcaster.py" name="tf_node_publisher" 
      
    </node>

Then i have a node named “tf_node_publisher” , do i understand correctly ?

Because i thought earlier that i have to use the same node name specified in the python script, in order to find static_transform_publisher script in the tf package, i typed " roscd tf " in the console and searched for the static_transform_publisher script, but i couldnt find the script.

Hello @erdemersan,

your understanding is correct. All that matters in a launch file is the pkg and type. The name you choose freely and it will override the name that you have specified in the python script.

Cheers,

Roberto