2017-12-05 2 views
-1

코딩을 위해 파이썬을 사용하는 라스베리 파이와 함께 gps 칩을 사용하고 있으며, GPS에서 속도를 얻고 1 초 루프를 사용하여 루프에서 mph로 변환하려고합니다.파이썬에서 gps의 속도를 어떻게 찾을 수 있습니까?

어떻게하면 상당히 정확한 데이터를 얻을 수 있습니까? 현재 다음 코드를 사용 중입니다 :

From gps import * 
import time 
import threading 
import math 
import RPi.GPIO as GPIO ## Import GPIO library 
import time ## Import 'time' library. Allows us to use 'sleep' 

GPIO.setmode(GPIO.BOARD) ## Use board pin numbering 
GPIO.setup(40,GPIO.OUT) ## Setup GPIO Pin 40 to OUT 

class GpsController(threading.Thread): 
    def __init__(self): 
     threading.Thread.__init__(self) 
     self.gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info 
     self.running = False 

    def run(self): 
     self.running = True 
     while self.running: 
      # grab EACH set of gpsd info to clear the buffer 
      self.gpsd.next() 

    def stopController(self): 
     self.running = False 

    @property 
    def fix(self): 
     return self.gpsd.fix 

    @property 
    def utc(self): 
     return self.gpsd.utc 

    @property 
    def satellites(self): 
     return self.gpsd.satellites 

mph = 15 

if __name__ == '__main__': 
    # create the controller 
    gpsc = GpsController() 
    try: 
     # start controller 
     gpsc.start() 
     while True: 
      if gpsc.fix.speed < mph : 
       print "speed is under 15 mph",gpsc.fix.speed 
       print mph 
       GPIO.output(40,GPIO.HIGH) 
       time.sleep(1) 
       GPIO.output(40,GPIO.LOW) 
       time.sleep(1) 
       #GPIO.output(40,True) 
       #time.sleep(.5) 
       #GPIO.output(40,False) 
       #time.sleep(.10) 

      elif gpsc.fix.speed > mph : 
       print "speed (m/s) ",gpsc.fix.speed 
       # GPIO.cleanup() 

      else: 
       print "fine" 
       #GPIO.cleanup() 

      #print "latitude ", gpsc.fix.laif 
      #print "longitude ", gpsc.fix.longitude 
      #print "time utc ", gpsc.utc, " + ", gpsc.fix.time 
      #print "altitude (m)", gpsc.fix.altitude 
      #print "eps ", gpsc.fix.eps 
      #print "epx ", gpsc.fix.epx 
      #print "epv ", gpsc.fix.epv 
      #print "ept ", gpsc.gpsd.fix.ept 
      #print "speed (m/s) ", gpsc.fix.speed 
      #print "climb ", gpsc.fix.climb 
      #print "track ", gpsc.fix.track 
      #print "mode ", gpsc.fix.mode 
      #print "sats ", gpsc.satellites 
      time.sleep(1) 

#Error 
    #except: 
    # print "Unexpected error:", sys.exc_info()[0] 
    # raise 

    #Ctrl C 
    except KeyboardInterrupt: 
     print "User cancelled" 

    finally: 
     print "Stopping gps controller" 
     gpsc.stopController() 
     #wait for the thread to finish 
     gpsc.join() 

    print "Done" 

GPIO.cleanup() 

현재 코드는 나에게 독서를 제공하지만 약 15mph의 동기화되지 않은 것으로 보입니다.

+0

시작 지점을 제공하십시오 (예 : 시도한 코드, 칩에서 출력 한 내용) – brddawg

+0

m/s 또는 mph를 찾고 계십니까? 아무데도 전환이없는 것처럼 보이지만 데이터가 m/s이고 mph와 비교하고 있습니다. – poompt

+0

mph로 변환하고 싶습니다 – Byrne

답변

0

칩에서 GPS 좌표를 가져와 cartesian coordinates으로 변환하고 이전 초에서 현재 초를 빼야합니다. 두 점 사이의 거리는 1 초 이내에 이동 한 거리입니다. 이것은 저속에서 시끄 럽기 때문에 어떤 종류의 필터링을 원할 수 있습니다.

관련 문제