What I've done is created another while loop inside the main one that only focuses on reading the serial line. Once the $GPGGA line is acquired, it allows the code to move on. Now the time between acquisitions will be at MOST 1 second.
The old code looked something like this:
while(True):
line = ser.readline()
line = line.split(",")
if line[0] =='$GPGGA':
if init == True:
currenttime,Latitude,Longitude = parse_gps(line)
coord_i = lat_long_into_xyz(Latitude,Longitude)
coord_i = lat_long_into_xyz(Latitude,Longitude)
print coord_i
init = False
init = False
else:
currenttime,Latitude,Longitude = parse_gps(line)
coord = lat_long_into_xyz(Latitude,Longitude)
coord_x = coord[0] - coord_i[0
coord_y = coord[1] - coord_i[1]
~~~rest of code~~~The WORKING code now looks like this:
while (True)
line = ser.readline()
line = line.split(",")
while(line[0] != '$GPGGA'): #Until it gets the $GPGGA line, stay here
line = ser.readline()
line = ser.readline()
line = line.split(",")
while(line[0] != '$GPGGA'): #Until it gets the $GPGGA line, stay here
line = ser.readline()
line = line.split(",")
if init == True:
currenttime,Latitude,Longitude = parse_gps(line)
coord_i = lat_long_into_xyz(Latitude,Longitude)
coord_i = lat_long_into_xyz(Latitude,Longitude)
print coord_i
init = False
init = False
else:
currenttime,Latitude,Longitude = parse_gps(line)
coord = lat_long_into_xyz(Latitude,Longitude)
coord_x = coord[0] - coord_i[0]
coord_y = coord[1] - coord_i[1]
Great job Andy. This is still blocking the entire program until it gets a valid GPS update. The compass is thus only updated at the same data rate as the GPS. With the Venus this shouldn't be a problem. It will require more thought in the future. You might want to read a bit about threading in python.
ReplyDelete