简体   繁体   English

Dronekit Python没有转到特定位置

[英]Dronekit Python didn't go to specific location

I have problem about Dronekit on Python 我在Python上有关于Dronekit的问题

My project about receive GPS Location from Android application and Launch drone flying to that Position, Everything work fine but problem is Drone can takeoff but drone didn't go to that Location(Testing 10+ times work only 1 time) 我的项目是从Android应用程序接收GPS位置,然后将无人机发射到该位置,一切正常,但问题是无人机可以起飞,但无人机没有去那个位置(测试10次以上只能工作1次)

Here is my code (I think problem is GlobalRelative) 这是我的代码(我认为问题是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")

Alternative, If I can't fix this problem I want to use MissionPlanner( I test on it , and it work) But I want to wait for GPS Location from Phone, and Launch the mission( every thing must automatic ) I have no idea how to bypass MissionPlanner 或者,如果我无法解决此问题,我想使用MissionPlanner(我对其进行测试,并且可以正常工作),但是我想等待Phone的GPS定位,然后启动任务(每件事必须自动进行),我不知道如何绕过MissionPlanner

The line: wp1 = LocationGlobalRelative(x, y, 10) only assign wp1 variable with a location coordinate. 行: wp1 = LocationGlobalRelative(x, y, 10)仅将wp1变量分配给位置坐标。 You can use vehicle.simple_goto(wp1) . 您可以使用vehicle.simple_goto(wp1) simple_goto is a built in function in dronekit to command the vehicle to specific coordinate you can read more about it here http://python.dronekit.io/automodule.html?highlight=simple_goto#dronekit.Vehicle.simple_goto simple_goto是dronekit中的内置函数,用于命令车辆达到特定坐标,您可以在此处了解更多信息http://python.dronekit.io/automodule.html?highlight=simple_goto#dronekit.Vehicle.simple_goto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM