위치 추적기로 사용하기 위해 나무 딸기 파이로 응용 프로그램을 개발 중입니다. 나는 라스베리 파이에서 위치 데이터를 얻기 위해 USB 인터페이스를 통해 신 6m GPS를 사용하고 있습니다. 이를 위해 GPS 직렬 장치를 가리 키도록 GPSD를 설정하고 있습니다.이동 장치에 해당하는 GPS 읽기가 변경되지 않습니다
다음 파이썬 스크립트를 폴링 GPSD 데몬 (instructions 참조) 및 유닉스 도메인 소켓을 통해 부모 프로세스에 위치 데이터를 전송합니다
#!/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)
이 코드를 실행하기 위해 라즈베리 파이 설정을 이동하면 1 킬로미터 떨어져서, 나는 콘솔에서 인쇄 된 새로운 독특한 lat-long 값을 볼 수있다. 그러나이 값을 그릴 때이 모든 위치가 시작 지점에 있음을 알았습니다. 즉, 모든 값은 동일한 시작점 주위에 묶입니다. 나는 1km 떨어진 지점까지 명확한 경로를 볼 수 없다.
내 코드에 문제가 있는지 확인하려면 raspberry pi에 "navit"소프트웨어를 설치하고 GPSD 데몬을 가리켰습니다. 내 경로를 그리기 위해 navit을 사용했을 때지도에서 올바르게 진행되었다는 것을 알 수있었습니다. 그래서 문제는 제 코드와 관련이 있다고 결론을 내 렸습니다.
은 누군가를 살펴보고 내가 문제를 파악
은 왜'gps_str = ': {.8f 1} {.8f 0}'에서'0'과'1'과 위도 길이를 포맷 할 gpsd.fix.longitude)' – am05mhz
알았어, 신경 쓰지 마, 삐걱 거리고 바보 같은 질문을해라 ^^ – am05mhz