[英]Ardupilot - Dronekit Setting the Current Location of the Vehicle
大家好,希望你們一切都好。
我正在做一個項目,我通過 SQL 服務器從 Android 設備接收 GPS 數據(經度和緯度)。 我想做的是將這個經度 - 緯度數據發送到我在 Ardupilot 的 SITL 車輛。 我考慮過這樣使用 Dronekit Python API:
from dronekit import connect, VehicleMode
import time
import mysql.connector
import time
#--- Start the Software In The Loop (SITL)
import dronekit_sitl
#
sitl = dronekit_sitl.start_default() #(sitl.start)
#connection_string = sitl.connection_string()
mydb = mysql.connector.connect(
host="******",
user="******",
password="*****",
database="koordinat"
)
mycursor = mydb.cursor()
#--- Now that we have started the SITL and we have the connection string (basically the ip and udp port)...
print("Araca bağlanılıyor")
vehicle = connect('tcp:127.0.0.1:5762', wait_ready=False, baud = 115200)
vehicle.wait_ready(True, raise_exception=False)
#-- Read information from the autopilot:
#- Version and attributes
vehicle.wait_ready('autopilot_version')
print('Autopilot version: %s'%vehicle.version)
#- Does the firmware support the companion pc to set the attitude?
print('Supports set attitude from companion: %s'%vehicle.capabilities.set_attitude_target_local_ned)
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
while(True):
mycursor.execute("SELECT * FROM koordinat WHERE 1")
location = str(mycursor.fetchall())
location = location.split(",")
location[0] = location[0].replace("[", "")
location[0] = location[0].replace("(", "")
location[0] = location[0].replace("'", "")
location[1] = location[1].replace("[", "")
location[1] = location[1].replace(")", "")
location[1] = location[1].replace("'", "")
location[1] = location[1].replace(")", "")
# Converting the longitude and latitude to float, before assigning to the vehicle GPS data:
location[0] = float(location[0])
location[1] = float(location[1])
# Setting the location of the vehicle:
vehicle.location.global_frame.lat = location[0]
vehicle.location.global_frame.lon = location[1]
print('Konum:', str(vehicle.location.global_frame.lat)+str(","), str(vehicle.location.global_frame.lon)+str(","), str(vehicle.location.global_frame.alt))
#- When did we receive the last heartbeat
print('Son bilgi gelişi: %s'%vehicle.last_heartbeat)
time.sleep(1)
但是,當我從 SITL 和 Mission Planner(也從我的代碼的打印語句)檢查時,位置沒有改變; 模擬器只是忽略了 Dronekit 發送的那些命令。 有沒有一種工作方法可以完成我想做的事情? 我試圖更改用於啟動模擬的 sim_vehicle.py 腳本。 但我只能更改車輛的起始/起始位置。 我無法在 SITL 和 Mission Planner 上更改車輛的當前位置。
這是不正確的。 您正在修改連接到 SITL 的車輛 object 的屬性,而不是向實際的自動駕駛儀發送任何命令。
vehicle.location.global_frame.lat = location[0]
vehicle.location.global_frame.lon = location[1]
你想要做的是將模式設置為 GUIDED 並使用 dronekit 中的simple_goto function 使無人機移動到 lat/lon/alt 坐標。
否則,您也可以發送此 MAVLink 命令SET_POSITION_TARGET_GLOBAL_INT來引導它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.