2

我目前正在尝试编写一个基于 GPSd 库的 python (2.7) 脚本,以使用 adafruit Ultimate GPS 覆盆子 Pi Hat ( https://www.adafruit.com/product/2324 ) 以 10Hz 的更新速率提供 GPS 速度数据) 时间戳也报告为 0.1 秒。

该模块本身的更新速率最高可达 10Hz,但在设置时默认为 1Hz,目前我无法成功提高它。我已经尝试发出 PMTK 命令(https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf)以提高更新率,但无法使其正常工作(PMTK220)并且包括将波特率设置为最大值值为 115200。

我已经到处搜索了一种增加更新率输出的方法,但是看不出问题出在哪里。下面的代码以超过 10 Hz 的速度打印出响应,但是这些值仅每 1 秒更新一次。

import os
import serial
from gps import *
import datetime
import time
import threading
import subprocess

#### CURRENTLY TRYING TO INCREASE GPS POLLING UPDATE RATE FROM DEFAULT 1Hz to 10Hz

subprocess.call(["stty","-F","/dev/serial0","raw","115200","cs8","clocal","-cstopb"])
subprocess.call(["sudo","systemctl","stop","gpsd.socket"])
subprocess.call(["sudo","systemctl","disable","gpsd.socket"])
subprocess.call(["sudo","gpsd","/dev/ttyS0","-F","/var/run/gpsd.sock"])

subprocess.call(["echo","-e","$PMTK251,115200*27\r\n","/dev/ttyS0"]) # command to set baudrate of serial port
subprocess.call(["echo","-e","$PMTK220,100*2F\r\n","/dev/ttyS0"]) #command to set GPS Update Rate

gpsd = None #seting the global variable

os.system('clear') #clear the terminal (optional)

class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
   self.running = True #setting the thread running to true

  def run(self):
    global gpsd
    while gpsp.running:
      gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer

gpsp = GpsPoller() # create the thread
gpsp.start() # start it up
os.system('clear')

x = 0
while x < 20: # infinite loop- use ctrl + c to end
    print gpsd.utc # print timestamp
    print gpsd.fix.speed # print gps speed
    print '-----------------'
    time.sleep(0.025) # Set print rate much higher than maximum possible of 10 Hz update rate

GPS脚本输出

4

1 回答 1

2

可能有点晚了,但模块默认设置为 9600 速率,iirc。尝试先在 Pi 上将波特率设置为 9600,然后发送 $PMTK251,115200 行。现在将 Pi 上的速率更改为 115200 并发送 10hz 部分 ($PMTK220,100*2F\r\n)

于 2020-07-20T12:22:28.727 回答