Ardupilot-无人机套件设置车辆的当前位置



大家好,希望你们一切顺利。

我正在做一个项目,在这个项目中,我通过SQL服务器从Android设备接收GPS数据(经度和纬度(。我想做的是将这些经度-纬度数据发送到我在阿杜皮洛特的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的车辆对象的属性,而不是向实际的自动驾驶仪发送任何命令。

vehicle.location.global_frame.lat = location[0]
vehicle.location.global_frame.lon = location[1]

您要做的是将模式设置为GUIDED,并使用dronekit中的simple_goto函数使无人机移动到lat/lon/alt坐标。

否则,您也可以发送此MAVLink命令SET_POSITION_TARGET_GLOBAL_INT来指导它。

最新更新