-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtb3_4
94 lines (73 loc) · 2.96 KB
/
tb3_4
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
#################################################################################
# Copyright 2018 IWIN, SJTU
#
# https://iwin-fins.com
#################################################################################
# Authors: Hongbo Li, Han Wang#
import rospy
from geometry_msgs.msg import Twist, Point, Quaternion
import tf
from math import radians, copysign, sqrt, pow, pi, atan2,cos,sin
from tf.transformations import euler_from_quaternion
import numpy as np
msg = """
control your Turtlebot3!
-----------------------
this is tb3_4
-----------------------
"""
class GotoPoint():
def __init__(self):
rospy.init_node('tb3_4', anonymous=False)
rospy.on_shutdown(self.shutdown)
self.cmd_vel = rospy.Publisher('cmd_vel', Twist, queue_size=5)#5
self.tb3_4_vel=rospy.Publisher('/tb3_4_vel',Twist,queue_size=5)#5
position = Point()
move_cmd = Twist()
r = rospy.Rate(10)
self.tf_listener = tf.TransformListener()
self.odom_frame = '/tb3_4/odom'
try:
self.tf_listener.waitForTransform(self.odom_frame, '/tb3_4/base_footprint', rospy.Time(), rospy.Duration(1.0))
self.base_frame = '/tb3_4/base_footprint'
except (tf.Exception, tf.ConnectivityException, tf.LookupException):
try:
self.tf_listener.waitForTransform(self.odom_frame, '/tb3_4/base_link', rospy.Time(), rospy.Duration(1.0))
self.base_frame = '/tb3_4/base_link'
except (tf.Exception, tf.ConnectivityException, tf.LookupException):
rospy.loginfo("Cannot find transform between odom and base_link or base_footprint")
rospy.signal_shutdown("tf Exception")
(position, rotation) = self.get_odom()
self.tb3_4_pos=rospy.Publisher('/tb3_4_pos',Point,queue_size=5)#10
self.tb3_4_pos.publish(position)
tb3_4_rot=Point()
tb3_4_rot.x=rotation
self.tb3_4_ori=rospy.Publisher('/tb3_4_rot',Point,queue_size=5)#10
self.tb3_4_ori.publish(tb3_4_rot)
president=Twist()
president.linear.x=0.5
president.angular.z=0.5
# president.angular.z=0.5
# print president
# print position.x
self.cmd_vel.publish(president)
self.tb3_4_vel.publish(president)
def get_odom(self):
try:
(trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0))
rotation = euler_from_quaternion(rot)
except (tf.Exception, tf.ConnectivityException, tf.LookupException):
rospy.loginfo("TF Exception")
return
return (Point(*trans), rotation[2])
def shutdown(self):
self.cmd_vel.publish(Twist())
rospy.sleep(1)
if __name__ == '__main__':
try:
while not rospy.is_shutdown():
print(msg)
GotoPoint()
except:
rospy.loginfo("shutdown program.")