with the following code I'm trying to add a gps point over a map using a raspberry pi 3:
from gps import *
import matplotlib.pyplot as plt
import time, inspect, os
logPath = "/home/solergy/IBUZ/LOGS/"
inputMapFilePath = logPath + "srcMap/" + "TBM-min.png"
actualOutMapFilePath = logPath + "Map_GPS"
TRX = -12.653 #top right longitude
TRY = 41.8675 #top right latitude
BLX = -12.6332 #bottom left longitude
BLY = 41.8619 #bottom left latitude
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
im = plt.imread(inputMapFilePath)
try:
while True:
report = gpsd.next() #
if report['class'] == 'TPV':
GPStime = str(getattr(report,'time',''))
lat = str(getattr(report,'lat',0.0))
lon = str(getattr(report,'lon',0.0))
speed = str(getattr(report,'speed','nan'))
# Create Image File
pos_y = float(lat)
pos_x = -float(lon)
actualTime = time.strftime("%H-%M-%S", time.localtime())
plt.text(BLX, BLY, actualTime)
plt.imshow(im, extent=[BLX, TRX, BLY, TRY], zorder=1)
plt.scatter(x=[pos_x], y=[pos_y], s=3, c='r', zorder=2)
cur_axes = plt.gca()
cur_axes.axes.get_xaxis().set_visible(False)
cur_axes.axes.get_yaxis().set_visible(False)
plt.savefig(actualOutMapFilePath, dpi=150, type="png")
plt.close('all')
print (actualTime , GPStime)
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
f.close()
f_now.close()
my problem is that I need to update this map at least every second (10Hz is better). The problem is not the gps part but the matplotlib that produce this image. Any idea about how to achieve a higher speed for this code? Antonio