-
Notifications
You must be signed in to change notification settings - Fork 2
/
GPSController.py
73 lines (62 loc) · 1.92 KB
/
GPSController.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
73
from gps import *
import time
import threading
import math
class GpsController(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.running = False
def run(self):
self.running = True
while self.running:
# grab EACH set of gpsd info to clear the buffer
self.gpsd.next()
def stopController(self):
self.running = False
@property
def fix(self):
return self.gpsd.fix
@property
def utc(self):
return self.gpsd.utc
@property
def satellites(self):
return self.gpsd.satellites
if __name__ == '__main__':
# create the controller
gpsc = GpsController()
try:
# start controller
gpsc.start()
while True:
if ( len(gpsc.satellites) > 0 ):
print "latitude ", gpsc.fix.latitude
print "longitude ", gpsc.fix.longitude
print "time utc ", gpsc.utc, " + ", gpsc.fix.time
print "altitude (m)", gpsc.fix.altitude
print "eps ", gpsc.fix.eps
print "epx ", gpsc.fix.epx
print "epv ", gpsc.fix.epv
print "ept ", gpsc.gpsd.fix.ept
print "speed (m/s) ", gpsc.fix.speed
print "climb ", gpsc.fix.climb
print "track ", gpsc.fix.track
print "mode ", gpsc.fix.mode
print "sats ", gpsc.satellites
else:
print "Looking for satellites"
time.sleep(1)
#Ctrl C
except KeyboardInterrupt:
print "User cancelled"
#Error
except:
print "Unexpected error:", sys.exc_info()[0]
raise
finally:
print "Stopping gps controller"
gpsc.stopController()
#wait for the tread to finish
gpsc.join()
print "Done"