1

私はロボットを作ろうとしていて、オンラインで見つけたチュートリアルに従っています。GPS をセットアップするときは、すべて正しくセットアップし、GPS クライアントを実行しました。cgps -s 動作し、接続が見つかりました!

ただし、チュートリアルの残りの部分に従って、システムの起動時に gps デーモンを開始し、python gps を使用してログ ファイルを作成し、それを Google マップまたは地球にインポートできるようにする必要がありました。私はそれが言ったコードを使用しましたが、ここに私のエラーがあります。

プログラムで使用される私のpythonコードは次のとおりです。

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
4

0 に答える 0