MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / GROVEGPS

Class GROVEGPS

Software/Python/Examples/gps_reading.py:27–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 ]
26
27class GROVEGPS():
28 def __init__(self,port='/dev/ttyAMA0',baud=9600,timeout=0):
29 self.ser = serial.Serial(port,baud,timeout=timeout)
30 self.ser.flush()
31 self.raw_line = ""
32 self.gga = []
33 self.validation =[] # contains compiled regex
34
35 # compile regex once to use later
36 for i in range(len(patterns)-1):
37 self.validation.append(re.compile(patterns[i]))
38
39 self.clean_data()
40 # self.get_date() # attempt to gete date from GPS.
41
42 def clean_data(self):
43 '''
44 clean_data:
45 ensures that all relevant GPS data is set to either empty string
46 or -1.0, or -1, depending on appropriate type
47 This occurs right after initialisation or
48 after 50 attemps to reach GPS
49 '''
50 self.timestamp = ""
51 self.lat = -1.0 # degrees minutes and decimals of minute
52 self.NS = ""
53 self.lon = -1.0
54 self.EW = ""
55 self.quality = -1
56 self.satellites = -1
57 self.altitude = -1.0
58
59 self.latitude = -1.0 #degrees and decimals
60 self.longitude = -1.0
61 self.fancylat = "" #
62
63 def get_date(self):
64 '''
65 attempt to get date from GPS data. So far no luck. GPS does
66 not seem to send date sentence at all
67 function is unfinished
68 '''
69 valid = False
70 for i in range(50):
71 time.sleep(0.5)
72 print (i)
73 self.raw_line = self.ser.readline().strip()
74 if self.raw_line[:6] == "GPZDA": # found date line!
75 print ("")
76 print (self.raw_line)
77
78
79 def read(self):
80 '''
81 Attempts 50 times at most to get valid data from GPS
82 Returns as soon as valid data is found
83 If valid data is not found, then clean up data in GPS instance
84 '''

Callers 1

gps_reading.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected