2017-10-16 30 views
1

我嘗試從dronekit運行示例腳本。代碼如下:Dronekit示例跟着我Python腳本不工作

import gps 
import socket 
import time 
from droneapi.lib import VehicleMode, Location 

def followme(): 
""" 
followme - A DroneAPI example 

This is a somewhat more 'meaty' example on how to use the DroneAPI. It uses the 
python gps package to read positions from the GPS attached to your laptop an 
every two seconds it sends a new goto command to the vehicle. 

To use this example: 
* Run mavproxy.py with the correct options to connect to your vehicle 
* module load api 
* api start <path-to-follow_me.py> 

When you want to stop follow-me, either change vehicle modes from your RC 
transmitter or type "api stop". 
""" 
try: 
    # First get an instance of the API endpoint (the connect via web case will be similar) 
    api = local_connect() 

    # Now get our vehicle (we assume the user is trying to control the first vehicle attached to the GCS) 
    v = api.get_vehicles()[0] 

    # Don't let the user try to fly while the board is still booting 
    if v.mode.name == "INITIALISING": 
     print "Vehicle still booting, try again later" 
     return 

    cmds = v.commands 
    is_guided = False # Have we sent at least one destination point? 

    # Use the python gps package to access the laptop GPS 
    gpsd = gps.gps(mode=gps.WATCH_ENABLE) 

    while not api.exit: 
     # This is necessary to read the GPS state from the laptop 
     gpsd.next() 

     if is_guided and v.mode.name != "GUIDED": 
      print "User has changed flight modes - aborting follow-me" 
      break 

     # Once we have a valid location (see gpsd documentation) we can start moving our vehicle around 
     if (gpsd.valid & gps.LATLON_SET) != 0: 
      altitude = 30 # in meters 
      dest = Location(gpsd.fix.latitude, gpsd.fix.longitude, altitude, is_relative=True) 
      print "Going to: %s" % dest 

      # A better implementation would only send new waypoints if the position had changed significantly 
      cmds.goto(dest) 
      is_guided = True 
      v.flush() 

      # Send a new target every two seconds 
      # For a complete implementation of follow me you'd want adjust this delay 
      time.sleep(2) 
except socket.error: 
    print "Error: gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh" 

followme() 

我嘗試在我的覆盆子與Raspbian操作系統上運行,但我得到了這樣的錯誤消息:

Error : gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh 

我得到一個感覺,我的覆盆子是在我可以運行這個腳本之前需要一個gps類型的設備來連接,但我真的不知道。 煩請告訴我什麼是錯用它..

指令的完整路徑,我從這裏得到: http://python.dronekit.io/1.5.0/examples/follow_me.html

回答

0

作爲例子說:

[這個例子]將使用一個USB GPS附在您的筆記本電腦上,讓您的車輛在您周圍漫步時跟隨您。

沒有GPS設備,代碼不知道你在哪裏,所以它不可能實現任何類型的「跟隨」行爲。在運行該示例之前,您需要:

  • 獲取某種GPS設備(我使用one of these,但有很多選擇)。
  • 在您的筆記本電腦上配置gpsd以與GPS設備連接。
+0

如何配置gpsd以及如何在筆記本電腦中使用gpsd?我非常困難,下面我附加了一個錯誤,當腳本示例跟着我跑 –