gpt4 book ai didi

python - 为什么使用python zero或Nan输出GPS?

转载 作者:行者123 更新时间:2023-12-02 03:46:28 24 4
gpt4 key购买 nike

我的 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 []

那么有人知道为什么这都是零且未知吗?

请帮忙,我现在正在尝试修复它一个星期。

谢谢

最佳答案

我遇到了类似的问题 python-gps包裹在 .切换到 gps3为我做了诀窍:

from time import sleep
from gps3.agps3threaded import AGPS3mechanism

agps_thread = AGPS3mechanism()
agps_thread.stream_data()
agps_thread.run_thread()

while True:
print('{},{}'.format(agps_thread.data_stream.lat, agps_thread.data_stream.lon))
sleep(2)

也就是说,第一项总是 n/a,n/a出于某种原因,但随后的值显示了正确的数据,而早先的情况并非如此。

关于python - 为什么使用python zero或Nan输出GPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com