-
Notifications
You must be signed in to change notification settings - Fork 3
/
vel_con.py
74 lines (56 loc) · 1.69 KB
/
vel_con.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
from mavros_msgs.msg import State
from mavros_msgs.srv import CommandBool, SetMode
from geometry_msgs.msg import Pose, PoseStamped, Point, Quaternion
import math
import numpy
from geometry_msgs.msg import Twist
from std_msgs.msg import Header
from threading import Thread
x=1
print x
def start1():
global x
rate = rospy.Rate(20) # Hz
if x==1:
print "Arming"
result = arming_srv(value=True)
print result
print "Setting Offboard Mode"
result = mode_srv(custom_mode="OFFBOARD")
print result
x=0
print "position_set"
while not rospy.is_shutdown():
print "Setting Offboard Mode"
result = mode_srv(custom_mode="OFFBOARD")
print result
x=0
pos=set_p()
pos.header.stamp = rospy.Time.now()
vel_pub.publish(pos)
try:
rate.sleep()
except rospy.ROSInterruptException:
pass
def state_cb(msg):
print msg
def set_p():
pos=PoseStamped()
pos.header = Header()
#enter position for the drone
pos.pose.position.x=0
pos.pose.position.y=0
pos.pose.position.z=5.0
return pos
if __name__ == '__main__':
rospy.init_node('subnode', anonymous=True)
vel_pub = rospy.Publisher('/mavros/setpoint_position/local', PoseStamped,queue_size=1)
arming_srv = rospy.ServiceProxy("/mavros/cmd/arming", CommandBool)
mode_srv = rospy.ServiceProxy("/mavros/set_mode", SetMode)
start1()
pos_thread = Thread(target=start1, args=())
pos_thread.daemon = True
pos_thread.start()
state_sub = rospy.Subscriber('/mavros/state', State, callback=state_cb)