尝试在raspberry pi上使用gps时出现Python代码错误
我正在尝试制作一个机器人,并且正在遵循我在网上找到的教程。 当我开始设置gps时,我把它设置好了,当我运行gps客户端时。cgps-s它工作了,它找到了一个连接 然而,我遵循了本教程的其余部分,它希望我在系统启动时启动gps守护进程,然后使用python gps生成一个日志文件,然后导入到google maps或earth中。我使用了上面的代码,下面是我的错误 以下是我在程序中使用的python代码:尝试在raspberry pi上使用gps时出现Python代码错误,python,gps,raspberry-pi,gpsd,Python,Gps,Raspberry Pi,Gpsd,我正在尝试制作一个机器人,并且正在遵循我在网上找到的教程。 当我开始设置gps时,我把它设置好了,当我运行gps客户端时。cgps-s它工作了,它找到了一个连接 然而,我遵循了本教程的其余部分,它希望我在系统启动时启动gps守护进程,然后使用python gps生成一个日志文件,然后导入到google maps或earth中。我使用了上面的代码,下面是我的错误 以下是我在程序中使用的python代码: from gps import * import time import threading
from gps import *
import time
import threading
f = open("locations.csv", "w")
gpsd = None
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd
gpsd = gps(mode=WATCH_ENABLE)
self.current_value = None
self.running = True
def run(self):
global gpsd
while gpsp.running:
gpsd.next()
if __name__ == '__main__':
gpsp = GpsPoller()
try:
gpsp.start()
while True:
f.write(str(gpsd.fix.longitude)
+ "," + str(gpsd.fix.latitude)
+ "\n")
time.sleep(30)
except(KeyboardInterrupt, SystemExit):
f.close()
gpsp.running = False
gpsp.join()
这是我运行该程序时遇到的错误,程序名为gps.py:
Traceback (most recent call last):
File "gps.py", line 9, in <module>
class GpsPoller(threading.Thread):
File "gps.py", line 23, in GpsPoller
gpsp = GpsPoller()
File "/home/pi/Robot/gps.py", line 13, in __init__
gpsd = gps(mode=WATCH_ENABLE)
NameError: global name 'gps' is not defined
回溯(最近一次呼叫最后一次):
文件“gps.py”,第9行,在
GpsPoller类(threading.Thread):
文件“gps.py”,第23行,在GpsPoller中
gpsp=GpsPoller()
文件“/home/pi/Robot/gps.py”,第13行,在__
gpsd=gps(模式=监视启用)
名称错误:未定义全局名称“gps”
。。