-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlistener2
More file actions
32 lines (24 loc) · 842 Bytes
/
Copy pathlistener2
File metadata and controls
32 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import rospy
import tf
import math
from geometry_msgs.msg import Twist
if __name__ == '__main__':
rospy.init_node("return_to_origin")
listener = tf.TransformListener()
listener.waitForTransform("/base_footprint","/odom",rospy.Time(),rospy.Duration(10.0))
rospy.loginfo("test")
vel = rospy.Publisher('/cmd_vel_mux/input/navi',Twist, queue_size = 1)
rate = rospy.Rate(10.0)
while not rospy.is_shutdown():
(trans,rot) = listener.lookupTransform('base_footprint','/odom', rospy.Time(0))
angular = 4 * math.atan2(trans[1], trans[0])
#stops working here
linear = 0.5 * math.sqrt(trans[0] ** 2 + trans[1] ** 2)
cmd = Twist()
cmd.linear.x = 0.5
cmd.angular.z = rangular
rospy.loginfo(cmd)
vel.publish(cmd)
rospy.loginfo(angular)
rate.sleep()