簡體   English   中英

Dronekit Python沒有轉到特定位置

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

我在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(我對其進行測試,並且可以正常工作),但是我想等待Phone的GPS定位,然后啟動任務(每件事必須自動進行),我不知道如何繞過MissionPlanner

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM