-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.py
72 lines (56 loc) · 1.82 KB
/
set.py
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
#!/usr/bin/env python
import rospy
import time
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
import numpy as np
class VelocityMonitor(object):
def __init__(self, pub, goal):
self.pub = pub
self.goal = goal
def callback(self, msg):
x = msg.pose.pose.position.x
y = msg.pose.pose.position.y
z = msg.pose.pose.position.z
o1 = msg.pose.pose.orientation.w
o2 = msg.pose.pose.orientation.z
if np.abs(self.goal[2] - z) >= 0.1:
if self.goal[2] > z:
move_val = Twist()
move_val.linear.z = 1
self.pub.publish(move_val)
else:
move_val = Twist()
move_val.linear.z = -1
self.pub.publish(move_val)
elif x >= self.goal[0] + 0.1:
move_val = Twist()
move_val.linear.x = -1
self.pub.publish(move_val)
elif y >= self.goal[1] + 0.001:
move_val = Twist()
move_val.linear.y = -1
self.pub.publish(move_val)
elif o1 >= 0.707 + 0.01 and o2 >= -0.707 + 0.01:
move_val = Twist()
move_val.angular.z = -1
self.pub.publish(move_val)
else:
hover = Twist()
hover.linear.z = 0.0000001
hover.linear.y = 0.0000001
hover.linear.x = 0.0000001
self.pub.publish(hover)
def main():
rospy.init_node('set_location')
#goal = [-4.76, 0.4, 2.10]
goal = [-4.66, 1.4, 2.30]
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
monitor = VelocityMonitor(pub, goal)
rospy.Subscriber('/ground_truth/state', Odometry, monitor.callback)
rospy.spin()
if __name__ == '__main__':
try:
main()
except rospy.ROSInterruptException:
pass