【问题标题】:Dronekit Python didn't go to specific locationDronekit Python 没有去特定的位置
【发布时间】:2018-09-04 15:33:50
【问题描述】:

我对 Python 上的 Dronekit 有疑问

我关于从 Android 应用程序接收 GPS 位置的项目 并发射无人机飞到那个位置,一切正常,但问题是无人机可以起飞,但无人机没有到达那个位置(测试 10 次以上只工作 1 次)

这是我的代码(我认为问题是 GlobalRelative)

 # Import DroneKit-Python
from dronekit import connect, VehicleMode, LocationGlobalRelative
import time
import urllib2
import simplejson
import json
import requests


#Wait for json data
response = urllib2.urlopen("http://localhost:3000/posts")
data = simplejson.load(response)
print(data)
json_string = data[0]["Information"]

gps = json.loads(json_string)
x=gps['lat']
y=gps['lon']
r = requests.delete('http://localhost:3000/posts/1')
# Connect to the Vehicle.
print("Connecting")
vehicle = connect('com4', wait_ready=False, baud=57600)#; vehicle.wait_ready(True, timeout=300)
print("Connected")
# Get some vehicle attributes (state)
print "Get some vehicle attribute values:"
print " GPS: %s" % vehicle.gps_0
print " Battery: %s" % vehicle.battery
print " Last Heartbeat: %s" % vehicle.last_heartbeat
print " Is Armable?: %s" % vehicle.is_armable
print " System status: %s" % vehicle.system_status.state
print " Mode: %s" % vehicle.mode.name    # settable

# Takeoff Function
def arm_and_takeoff(tgt_altitude):
    print("Arming motors")

#   while not vehicle.is_armable:
#       time.sleep(1)

    vehicle.mode = VehicleMode("GUIDED")
    vehicle.armed = True

    print("Takeoff")
    vehicle.simple_takeoff(tgt_altitude)

    # wait reach tgt_altitude
    while True:
        altitude = vehicle.location.global_relative_frame.alt

        if altitude >= tgt_altitude -1:
            print("Altitude Reached")
            break

        time.sleep(1)

# Main
arm_and_takeoff(10)

# Speed
vehicle.airspeed = 7

# Go to wp
wp1 = LocationGlobalRelative(x, y, 10)

# Close vehicle object before exiting script

vehicle.mode = VehicleMode("RTL")
vehicle.close()


print("Completed")

替代方案,如果我无法解决此问题,我想使用 MissionPlanner(我对其进行了测试,它可以工作)但我想等待来自手机的 GPS 定位,然后启动任务(每件事都必须自动)我不知道如何绕过 MissionPlanner

【问题讨论】:

    标签: python dronekit-python dronekit mavlink


    【解决方案1】:

    该行:wp1 = LocationGlobalRelative(x, y, 10) 只为 wp1 变量分配位置坐标。您可以使用vehicle.simple_goto(wp1)。 simple_goto 是dronekit 中的一个内置函数,用于命令车辆到特定坐标,您可以在此处阅读更多相关信息http://python.dronekit.io/automodule.html?highlight=simple_goto#dronekit.Vehicle.simple_goto

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2012-09-23
      • 2016-06-18
      • 2020-04-14
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多