-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcurrentgps.py
70 lines (58 loc) · 1.45 KB
/
currentgps.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
#from ublox_gps import UbloxGps
import serial
from ublox_gps import UbloxGps
# Can also use SPI here - import spidev
# I2C is not supported
'''
def run():
port = serial.Serial('/dev/ttyACM0', baudrate=460800, timeout=1)
gps = UbloxGps(port)
try:
print("Listenting for UBX Messages.")
while True:
try:
coords = gps.geo_coords()
print(coords.lon, coords.lat)
except (ValueError, IOError) as err:
print(err)
finally:
port.close()
'''
def get_gps():
port = serial.Serial('/dev/ttyACM0', baudrate=460800, timeout=1)
gps = UbloxGps(port)
try:
try:
coords = gps.geo_coords()
current_lon = coords.lon
current_lat = coords.lat
#print(current_lon, current_lat)
except (ValueError, IOError)as err:
print(err)
finally:
port.close()
return current_lon, current_lat
#
#lon, lat = get_gps()
#print(lon,lat)
#except (ValueError, IOError) as err:
#print(err)
#finally:
#port.close()
#return current_lon, current_lat#127.076779433 , 37.2463380449
#a,b = get_gps()
#print(a,b)
# def continuous_get_gps():
# # try:
# try:
# coords = gps.geo_coords()
# global lon = coords.lon
# global lat = coords.lat
# print(lon, lat)
# except (ValueError, IOError) as err:
# print(err)
# # finally:
# # port.close()
# threading.Timer(1,continuous_get_gps).start()
# #return str(current_lon), str(current_lat)
# continuous_get_gps()