Ask Your Question

Unable to run Tutorial: tf2TutorialsWriting a tf2 broadcaster (Python)

asked 2019-10-17 17:43:37 -0600

Suyash gravatar image

updated 2019-10-18 10:48:40 -0600

gvdhoorn gravatar image


I am new to ROS and I am trying to complete the tf2 tutorials. While running this particular tutorial ( a tf2 broadcaster (Python)) I created the file and the start_demo.launch file exactly as described in the tutorial and in the directory as described in the tutorial. After this, I invoked catkin_make and I source devel_isolated/setup.bash in the terminal (I also tried sourcing devel/setup.bash). However, the following error comes up and it closes:

    RLException: Unable to launch [turtle1_tf2_broadcaster-4]. 
    If it is a script, you may be missing a '#!' declaration at the top.
    The traceback for the exception was written to the log file

The full output of the command I have attached at the end.

I am not able to figure out a way to get through this. Please suggest me what should I do. Please also find below my code for and start_demo.launch. On lines 5 and 22 in, I tried changing tf (as mentioned on the tutorial a tf2 broadcaster (Python)) to tf2 and it still didn't work.

   #!/usr/bin/env python  
   import rospy

   # Because of transformations
   import tf2_conversions

   import tf2_ros
   import geometry_msgs.msg
   import turtlesim.msg

   def handle_turtle_pose(msg, turtlename):
       br = tf2_ros.TransformBroadcaster()
       t = geometry_msgs.msg.TransformStamped()

       t.header.stamp =
       t.header.frame_id = "world"
       t.child_frame_id = turtlename
       t.transform.translation.x = msg.x
       t.transform.translation.y = msg.y
       t.transform.translation.z = 0.0
       q = tf2_conversions.transformations.quaternion_from_euler(0, 0, msg.theta)
       t.transform.rotation.x = q[0]
       t.transform.rotation.y = q[1]
       t.transform.rotation.z = q[2]
       t.transform.rotation.w = q[3]


   if __name__ == '__main__':
       turtlename = rospy.get_param('~turtle')
       rospy.Subscriber('/%s/pose' % turtlename,

Code for start_demo.launch

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

    <node name="turtle1_tf2_broadcaster" pkg="learning_tf2" type="" respawn="false" output="screen" >
      <param name="turtle" type="string" value="turtle1" />
    <node name="turtle2_tf2_broadcaster" pkg="learning_tf2" type="" respawn="false" output="screen" >
      <param name="turtle" type="string" value="turtle2" /> 


Full out put when lunching the start_demo.launch.

suyash@ROS:~/tutorial_ws$ roslaunch learning_tf2 start_demo.launch
... logging to /home/suyash/.ros/log/b7a6d97a-f1bb-11e9-a228-08002776bdd9/roslaunch-ROS-2614.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ROS:36971/


 * /rosdistro: melodic
 * /rosversion: 1.14.3
 * /turtle1_tf2_broadcaster/turtle: turtle1
 * /turtle2_tf2_broadcaster/turtle: turtle2

    sim (turtlesim/turtlesim_node)
    teleop (turtlesim/turtle_teleop_key)
    turtle1_tf2_broadcaster (learning_tf2/
    turtle2_tf2_broadcaster (learning_tf2/

auto-starting new master
process[master]: started with pid [2625]

setting /run_id to b7a6d97a-f1bb-11e9-a228-08002776bdd9
process[rosout-1]: started with pid [2636]
started core service [/rosout]
process[sim-2]: started with pid ...
edit retag flag offensive close merge delete


Always include links to tutorials, source code, pages etc you're reading, following or copy-pasting.

Without seeing what you're actually doing, we cannot help you.

Seeing the error message you received, please also show us what exactly you copied (ie: the contents of your copy of

gvdhoorn gravatar imagegvdhoorn ( 2019-10-18 04:50:25 -0600 )edit

Thank you for your response, sorry I missed those details. I have edited my question and included the details.Also one more update is I tried doing the tf tutorial as well ( a tf broadcaster (Python), and I am still getting the exact same error, so there is something fundamental that I am missing.

Suyash gravatar imageSuyash ( 2019-10-18 10:21:39 -0600 )edit

Please show us the exact contents of your

And also the output of ls -al (run it in the directory that contains the file).

gvdhoorn gravatar imagegvdhoorn ( 2019-10-18 10:28:09 -0600 )edit

I ran the command and the output was:

suyash@ROS:~/tutorial_ws/src/learning_tf2/nodes$ ls -al
-rwxr-xr-x 1 suyash suyash 1218 Oct 17 18:47

I have also copied and pasted the exact contents of Also I have included full output of roslaunch learning_tf2 start_demo.launch.

Suyash gravatar imageSuyash ( 2019-10-18 10:44:37 -0600 )edit

Hi there. Is there any update for me on this question?

Suyash gravatar imageSuyash ( 2019-10-21 10:28:10 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-10-23 22:29:36 -0600

Suyash gravatar image

Hi, I have figured out the solution. There was around 3 space characters between the start and #!/usr/bin/env python. When I removed the spaces for this line and all subsequent lines, it worked.

edit flag offensive delete link more


There was around 3 space characters between the start and #!/usr/bin/env python

This was indeed the reason why I asked you to copy the contents of your script verbatim.

Good to hear you figured it out.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-24 02:43:58 -0600 )edit

answered 2019-10-18 09:37:00 -0600

Alberto E. gravatar image

Hi Suyash,

Without more data, and assuming that you are following the ROS wiki tutorials, here:

The most probable cause for your error is that you missed the 1st line in your script, this one:

#!/usr/bin/env python

Basically, this line makes sure that your script is executed as a Python script. Try to add it at the top of your script and the error should be gone.

edit flag offensive delete link more


Hi Alberto.Thank you for your response and pardon me for the delayed response. I am using the same tutorial as mentioned by you. I actually found that the line of code is included in my script. Please take a look at my edited question ( I have added my codes). Also one more update is I tried doing the tf tutorial as well ( a tf broadcaster (Python)), and I am still getting the exact same error, so there is something fundamental that I am missing.

Suyash gravatar imageSuyash ( 2019-10-18 10:24:17 -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: 2019-10-17 17:43:37 -0600

Seen: 27 times

Last updated: Oct 18