Unable to run turtle_tf2_broadcaster.py. Tutorial: tf2TutorialsWriting a tf2 broadcaster (Python)
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):
br = tf2_ros.TransformBroadcaster()
t = geometry_msgs.msg.TransformStamped()
t.header.stamp = rospy.Time.now()
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]
br.sendTransform(t)
if __name__ == '__main__':
rospy.init_node('tf2_turtle_broadcaster')
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"/>
<node name="turtle1_tf2_broadcaster" pkg="learning_tf2" type="turtle_tf2_broadcaster.py" respawn="false" output="screen" >
<param name="turtle" type="string" value="turtle1" />
</node>
<node name="turtle2_tf2_broadcaster" pkg="learning_tf2" type="turtle_tf2_broadcaster.py" respawn="false" output="screen" >
<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 ...
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
).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.
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).I ran the command and the output was:
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.
Hi there. Is there any update for me on this question?