Ich entwickle eine Anwendung in Raspberry Pi, um es als Location-Tracker zu verwenden. Ich benutze Neo-6m GPS über USB-Schnittstelle, um die Positionsdaten in Raspberry Pi zu erhalten. Dazu richte ich GPSD ein, um auf das USB-Serial-Gerät zu zeigen. (Siehe instructions)GPS-Lesung ändert sich nicht entsprechend bewegtes Gerät
Die folgende Python-Skript fragt die RLAP Daemon und sendet die Standortdaten an dem übergeordneten Prozess über einen Unix-Domain-Socket:
#!/usr/bin/python
import os
from gps import *
from time import *
import time
import threading
import socket
import math
t1, t2 = socket.socketpair()
gpsd = None #seting the global variable
host = "localhost"
port = 8888
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE,host=host,port=port) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
print("%%%%%%%GPS RUN")
global gpsd
while self.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
time.sleep(3)
def poll_gps(socket):
print('GPS POLL')
gpsp = GpsPoller() # create the thread
gpsp.start()
try:
while True:
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc
#print 'latitude ' , gpsd.fix.latitude
#print 'longitude ' , gpsd.fix.longitude
if gpsd.fix.latitude is not None and gpsd.fix.longitude is not None and not math.isnan(gpsd.fix.longitude) and not math.isnan(gpsd.fix.latitude) and gpsd.fix.latitude != 0.0 and gpsd.fix.longitude != 0.0 :
gps_str='{0:.8f},{1:.8f}'.format(gpsd.fix.latitude, gpsd.fix.longitude)
dict_str="{'type' : 'gps', 'value' : '"+gps_str+"'}"
dict_str_new="{'type' : 'gps', 'value' : '"+str(gpsd.fix.latitude)+","+str(gpsd.fix.longitude)+"'}"
print("GPS123_OLD" +dict_str)
print("GPS123_NEW" +dict_str_new)
if socket == None:
print("GOT GPS VALUE")
sys.exit(0)
socket.sendall(dict_str+'\n')
else:
print('%%%%%%%%%%%%%%%%%%GPS reading returnd None!')
time.sleep(3) #set to whatever
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."
if __name__ == '__main__':
poll_gps(None)
Wenn ich diesen Code ausführen und die Raspberry Pi-Setup bewegen 1 Kilometer entfernt kann ich neue deutliche lat-long-Werte in der Konsole sehen. Aber wenn ich diese Werte zeichne, sehe ich, dass all diese Orte am Ausgangspunkt sind. Dh alle Werte sind um denselben Startpunkt gebündelt. Ich sehe keinen klaren Weg zum 1 km entfernten Punkt.
Um zu überprüfen, ob das Problem mit meinem Code ist oder nicht, habe ich "Navit" -Software in Raspberry Pi installiert und auf den GPSD-Daemon ausgerichtet. Als ich meinen Weg mit der Navi grafisch darstellte, wurde mein Fortschritt in der Karte korrekt angezeigt. Also habe ich festgestellt, dass das Problem mit meinem Code ist.
Kann jemand einen Blick und lassen Sie mich wissen, ob es eine Ausgabe mit meinem Code ist
warum forma Sie den lat-long mit '0' und '1' in 'gps_str = '{0: .8f}, {1: .8f}'. Format (gpsd.fix.latitude, gpsd.fix.longitude) ' – am05mhz
Hoppla, vergiss es, hab mich ablenken lassen und blöde Frage gestellt ^^ – am05mhz