【问题标题】:Dronekit Example Follow Me Python Script not workingDronekit 示例跟随我 Python 脚本不起作用
【发布时间】:2017-10-16 13:18:29
【问题描述】:

我尝试从dronekit 运行一个示例脚本。代码是这样的:

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 OS 的 Raspberry 中运行它,但我收到如下错误消息:

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

【问题讨论】:

    标签: dronekit-python dronekit


    【解决方案1】:

    正如例子所说:

    [此示例] 将使用连接到您的笔记本电脑的 USB GPS,让车辆在您在田野中行走时跟随您。

    没有 GPS 设备,代码不知道您在哪里,因此不可能实现任何类型的“跟随”行为。在运行示例之前,您需要:

    • 购买某种 GPS 设备(我使用 one of these,但有很多替代品)。
    • 在您的笔记本电脑上配置 gpsd 以与 GPS 设备连接。

    【讨论】:

    • 如何配置gpsd以及如何在笔记本电脑中使用gpsd?我很为难,下面我附上脚本示例跟随我运行时出现的错误
    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多