#! /usr/bin/env python
import sys
import rospy
import tf
import time
import math
from geometry_msgs.msg import Twist
def shutdown_callback():
global ctr_c
print("Program is shutting down")
cmd=Twist()
cmd.linear.x = 0.0
cmd.angular.z = 0.0
turtle_vel.publish(cmd)
ctrl_c = True
rospy.init_node('TF_listner_turtle')
listner = tf.TransformListener()
if len(sys.argv)<3:
print("usage: turtle_tf_listener.py follower_model_name model_to_be_followed_name")
else:
follower=sys.argv[0]
followed=sys.argv[1]
turtle_vel = rospy.Publisher(follower+'/cmd',Twist,queue_size=1)
rate = rospy.Rate(10.0)
ctr_c=False
follower_frame="/"+follower
followed_frame="/"+followed
rospy.on_shutdown(shutdown_callback)
while not ctr_c:
try:
(trans,rot)=listner.lookupTransform(follower_frame,followed_frame,rospy.Time(0))
except (tf.LookupException,tf.ConnectivityException,tf.ExtrapolationException):
continue
angular = 4 * math.atan2(trans[1], trans[0])
linear = 0.5 * math.sqrt(trans[0] ** 2 + trans[1] ** 2)
cmd = Twist()
cmd.linear.x = linear
cmd.angular.z = angular
turtle_vel.publish(cmd)
rate.sleep()``
This is the error i get
rosrun exercise21 translist.py turtle1 coke_can
the rosdep view is empty: call ‘sudo rosdep init’ and ‘rosdep update’
/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py:842: UserWarning: ‘/home/user/catkin_ws/src/exercise21/src/translist.py/cmd’ is not a legal ROS graph resource name. This may cause problems with other ROS tools
super(Publisher, self).init(name, data_class, Registration.PUB)
Warning: Invalid argument “/home/user/catkin_ws/src/exercise21/src/translist.py” passed to canTransform argument target_frame in tf2 frame_ids cannot start with a ‘/’ like:
at line 134 in /tmp/binarydeb/ros-kinetic-tf2-0.5.20/src/buffer_core.cpp
Traceback (most recent call last):
File “/home/user/catkin_ws/src/exercise21/src/translist.py”, line 36, in
(trans,rot)=listner.lookupTransform(follower_frame,followed_frame,rospy.Time(0))
File “/opt/ros/kinetic/lib/python2.7/dist-packages/tf/listener.py”, line 104, in lookupTransform
msg = self._buffer.lookup_transform(strip_leading_slash(target_frame), strip_leading_slash(source_frame), time)
File “/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/buffer.py”, line 87, in lookup_transform
return self.lookup_transform_core(target_frame, source_frame, time)
tf2.InvalidArgumentException: Invalid argument “/home/user/catkin_ws/src/exercise21/src/translist.py” passed to lookupTransform argument target_frame in tf2 frame_ids cannot start with a ‘/’ like: