-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsir2020_serial.py
More file actions
58 lines (42 loc) · 1.18 KB
/
sir2020_serial.py
File metadata and controls
58 lines (42 loc) · 1.18 KB
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
import serial
import time
import os
import string
import argparse
import cv2
import sys
import time
import math
os.system("sudo chmod a+rw /dev/ttyUSB0")
global ser
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout = 1)
data = open('data_map2.txt', 'w+')
ser.readline()
i = 0
while True:
line_gng = ser.readline() #$GNGGA
line_gph = ser.readline() #$GPHDT
print(line_gph)
gph_list = line_gph.decode().replace('\x00','').split(',')
if gph_list[0] == '$GNGGA': #except process
a = line_gph
line_gph = line_gng
line_gng = a
gph_list = line_gph.decode().replace('\x00','').split(',')
#heading_data = (float(gph_list[1])*180)/math.pi
heading_data = float(gph_list[1])
gng_list = line_gng.decode().replace('\x00','').split(',')
latitude0 = gng_list[2]
longitude0 = gng_list[4]
line = str(heading_data) + "," + str(latitude0) + "," + str(longitude0) + "\n"
print(line)
data.write(line)
time.sleep(0.01)
#i = i + 1
data.close()
"""
b'$GPHDT, 174.233,T*15\r\n'
b'$GNGGA,101905.69,3718.727361,N,12657.117765,E,1,08,1.0,73.5,M, 0.0, M,,0000*76\r\n'
b'$GPHDT, 174.246,T*17\r\n'
b'$GNGGA,101905.74,3718.727361,N,12657.117765,E,1,08,1.0,73.5,M, 0.0, M,,0000*7A\r\n'
"""