使用python渲染gpsd.fix.speed时获取NaN作为输出

时间:2014-08-06 04:13:17

标签: python pygame nan

我试图让pygame绘制gpsd.fix.speed的输出。由于某种原因,它正在绘制纳米。当我尝试打印gpsd.fix.speed时,我也得到了nan。当我使用cgps或xgps查看速度时,我可以看到速度很好。关于如何使其工作,或如何清理我的代码的任何想法(我确定它看起来不是很好)。

import pygame
import os
import sys
from gps import *
from time import *

size = (300,150)

pygame.init()

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Speedometer")

pygame.key.set_repeat()

gpsd = gps(mode=WATCH_ENABLE)

def showSpeedo(speedoScreen):
           global gpsd
           global gpsspeed
           speedoScreen.fill((0,0,0))
           myfont = pygame.font.SysFont(None, 100)

           gpsspeed = str(gpsd.fix.speed)

           speedolabel = myfont.render(gpsspeed, 1, (2, 120, 245))

           textpos = speedolabel.get_rect()
           textpos.centerx = speedoScreen.get_rect().centerx
           textpos.centery = speedoScreen.get_rect().centery

           speedoScreen.blit(speedolabel, textpos)

           pygame.display.flip()

quitloop=False

refresh = 0

while not quitloop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            quitloop = True
        if (event.type == pygame.KEYUP):
            if (event.key == pygame.K_q):
                quitloop = True

    if pygame.time.get_ticks() > refresh:
        showSpeedo(screen)
        refresh = pygame.time.get_ticks() + 500

 print "Exiting..."

非常感谢任何帮助!

0 个答案:

没有答案