-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfd_node.py
64 lines (49 loc) · 1.64 KB
/
rfd_node.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
import queue
import rospy
from std_msgs.msg import Int8
from sensor_msgs.msg import NavSatFix
from mavros_test_common import MavrosTestCommon
import serial
def rfd():
rospy.init_node('rfd', anonymous=True)
port = "/dev/ttyAMA0" #will most likely change
baud = 57600
timeout = 5
ser = serial.Serial(port = port, baudrate = baud, timeout = timeout)
pos = (0,0,0)
def position_callback(data):
global pos
pos = (float(data.latitude), float(data.longitude), float(data.altitude))
rospy.Subscriber('mavros/global_position/global', NavSatFix, position_callback)
ll = -1
def landingSubcallback(data):
global ll
ll = data.data
rospy.Subscriber('landing', Int8, landingSubcallback)
landing_pub = rospy.Publisher('landing', Int8, queue_size=2)
# wp_pub = rospy.Publisher('wp', NavSatFix, queue_size=10)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
rmsg = ser.read()
if rmsg.startswith('uciforgeugv0//'):
rdata = rmsg.split('//')
landing_pub.publish(int(rdata[1]))
'''
if rdata[1] == 'True':
z.data = True
else:
z.data = False
landing_pub.publish(z)
'''
'''
wp = rdata[2].split(':')
wpp = NavSatFix(latitude=wp[0],longitude=wp[1])
wp_pub.publish(wpp)
'''
smsg = 'uciforgeugv1//' + str(ll) + '//' + str(pos[0]) + ':' + str(pos[1])
ser.write(smsg)
ser.flushInput()
ser.flushOutput()
rate.sleep()
if __name__ == '__main__':
rfd()