我在 GPS 输出方面遇到问题。当我输入:
$ cat /dev/ttyUSB0
我有 NMEA 句子出来(这就是我想要的)
$GPGGA,134131.000,4548.0018,N,01557.1026,E,1,06,1.5,123.8,M,42.4,M,,0000*56
$GPGSA,A,3,12,15,24,17,22,18,,,,,,,2.3,1.5,1.8*30
$GPGSV,3,1,12,24,76,320,29,12,49,254,44,15,42,195,17,17,38,057,15*7A
$GPGSV,3,2,12,25,15,249,,09,12,112,,26,11,162,,18,09,267,19*75
$GPGSV,3,3,12,22,08,297,23,14,08,323,,04,06,114,,28,03,061,*78
$GPRMC,134131.000,A,4548.0018,N,01557.1026,E,1.71,291.64,210513,,,A*67
但是,当我尝试使用 python 查看输出时(这是基本代码):
import gps
session=gps.gps('localhost','2947')
session.stream()
print session
我懂了:
Time: (nan)
Lat/Lon: 0.000000 0.000000
Altitude: ?
Speed: ?
Track: ?
Status: STATUS_NO_FIX
Mode: MODE_NO_FIX
Quality: 0 p=0.00 h=0.00 v=0.00 t=0.00 g=0.00
Y: 0 satellites in view:
我尝试了别人的代码,但它总是说 NaN 或 0:
#! /usr/bin/python
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0
import os
from gps import *
from time import *
import time
import threading
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$
if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
gpsp.start() # start it up
while True:
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc
os.system('clear')
print
print ' GPS reading'
print '----------------------------------------'
print 'latitude ' , gpsd.fix.latitude
print 'longitude ' , gpsd.fix.longitude
print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
print 'altitude (m)' , gpsd.fix.altitude
print 'eps ' , gpsd.fix.eps
print 'epx ' , gpsd.fix.epx
print 'epv ' , gpsd.fix.epv
print 'ept ' , gpsd.fix.ept
print 'speed (m/s) ' , gpsd.fix.speed
print 'climb ' , gpsd.fix.climb
print 'track ' , gpsd.fix.track
print 'mode ' , gpsd.fix.mode
print
print 'sats ' , gpsd.satellites
time.sleep(5) #set to whatever
输出:
GPS reading
----------------------------------------
latitude 0.0
longitude 0.0
time utc + nan
altitude (m) nan
eps nan
epx nan
epv nan
ept nan
speed (m/s) nan
climb nan
track nan
mode 1
sats []
那么有人知道为什么这一切都是零和未知的吗?
请帮忙,我正在尝试修复它一个星期。
谢谢