Hello,

I am new to ROS and I am trying to complete the tf2 tutorials. While running this particular tutorial (http://wiki.ros.org/tf2/Tutorials/Wri... a tf2 broadcaster (Python)) I created the turtle_tf2_broadcaster.py 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 turtle_tf2_broadcaster.py and start_demo.launch. On lines 5 and 22 in turtle_tf2_broadcaster.py, I tried changing tf (as mentioned on the tutorial http://wiki.ros.org/tf2/Tutorials/Wri... 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):
t = geometry_msgs.msg.TransformStamped()

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]

br.sendTransform(t)

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


Code for start_demo.launch

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

<param name="turtle" type="string" value="turtle1" />
</node>
<param name="turtle" type="string" value="turtle2" />
</node>

</launch>


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/ SUMMARY ======== PARAMETERS * /rosdistro: melodic * /rosversion: 1.14.3 * /turtle1_tf2_broadcaster/turtle: turtle1 * /turtle2_tf2_broadcaster/turtle: turtle2 NODES / sim (turtlesim/turtlesim_node) teleop (turtlesim/turtle_teleop_key) turtle1_tf2_broadcaster (learning_tf2/turtle_tf2_broadcaster.py) turtle2_tf2_broadcaster (learning_tf2/turtle_tf2_broadcaster.py) auto-starting new master process[master]: started with pid [2625] ROS_MASTER_URI=http://localhost:11311 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 close merge delete ## Comments 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 turtle_tf2_broadcaster.py). ( 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 (http://wiki.ros.org/tf/Tutorials/Writing a tf broadcaster (Python), and I am still getting the exact same error, so there is something fundamental that I am missing. ( 2019-10-18 10:21:39 -0600 )edit Please show us the exact contents of your turtle_tf2_broadcaster.py. And also the output of ls -al turtle_tf2_broadcaster.py (run it in the directory that contains the file). ( 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 turtle_tf2_broadcaster.py
-rwxr-xr-x 1 suyash suyash 1218 Oct 17 18:47 turtle_tf2_broadcaster.py
suyash@ROS:~/tutorial_ws/src/learning_tf2/nodes\$


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

( 2019-10-18 10:44:37 -0600 )edit

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

( 2019-10-21 10:28:10 -0600 )edit

Sort by » oldest newest most voted

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.

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.

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

Hi Suyash,

Without more data, and assuming that you are following the ROS wiki tutorials, here: http://wiki.ros.org/tf2/Tutorials/Wri...

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.

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 (http://wiki.ros.org/tf/Tutorials/Writing a tf broadcaster (Python)), and I am still getting the exact same error, so there is something fundamental that I am missing.

( 2019-10-18 10:24:17 -0600 )edit