我对Python上的Dronekit有问题
我的项目是从安卓应用程序接收全球定位系统位置并发射无人机飞到那个位置,一切都正常,但问题是无人机可以起飞,但无人机没有去那个位置(测试10+时间只有一次)
下面是我的代码(我认为问题出在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
发布于 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
https://stackoverflow.com/questions/49492318
复制相似问题