-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfd_node_gs.py
69 lines (50 loc) · 1.76 KB
/
rfd_node_gs.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
import string
from tokenize import String
import rospy
from std_msgs.msg import Int8, String
from sensor_msgs.msg import NavSatFix
from mavros_test_common import MavrosTestCommon
import serial
import time
def rfd():
rospy.init_node('rfd_gs', anonymous=True)
port = "COM5" #will most likely change
baud = 57600
timeout = 5
ser = serial.Serial(port = port, baudrate = baud, timeout = timeout)
'''
# for if we need to dynamically get waypoint if it isnt given to us before
wp = (0,0,0)
def position_callback(data):
global wp
wp = (float(data.latitude), float(data.longitude), float(data.altitude))
rospy.Subscriber('ugv_waypoint', NavSatFix, position_callback)
'''
ll = False
def landing_callback(data):
global ll
ll = data.data
rospy.Subscriber('ugv_landing', Int8, landing_callback)
landed_pub = rospy.Publisher('ugv_landing', Int8, queue_size=2)
pos_pub = rospy.Publisher('ugv_position', NavSatFix, queue_size=10)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
smsg = 'uciforgeugv0//' + str(ll) # + '//' + str(wp[0]) + ':' + str(wp[1])
ser.write(smsg)
time.sleep(5)
rmsg = ser.read()
if rmsg.startswith('uciforgeugv1//'):
rdata = rmsg.split('//')
if rdata[1] == 'True':
z.data = True
else:
z.data = False
landed_pub.publish(z) # this publishes so another decoupling node can reel back in drone
pos = rdata[2].split(':')
poss = NavSatFix(latitude=pos[0],longitude=pos[1])
pos_pub.publish(poss)
ser.flushInput()
ser.flushOutput()
rate.sleep()
if __name__ == '__main__':
rfd()