首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dronekit Python未转到特定位置

Dronekit Python未转到特定位置
EN

Stack Overflow用户
提问于 2018-03-26 21:11:09
回答 1查看 430关注 0票数 0

我对Python上的Dronekit有问题

我的项目是从安卓应用程序接收全球定位系统位置并发射无人机飞到那个位置,一切都正常,但问题是无人机可以起飞,但无人机没有去那个位置(测试10+时间只有一次)

下面是我的代码(我认为问题出在GlobalRelative)

代码语言:javascript
复制
 # 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

EN

回答 1

Stack Overflow用户

发布于 2018-08-31 13:56:33

行: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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49492318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档