python - Ardupilot - Dronekit 设置车辆的当前位置
问题描述
大家好,希望你们一切都好。
我正在做一个项目,我通过 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 上更改车辆的当前位置。
解决方案
推荐阅读
- python - 为什么python函数使用相同的参数返回不同的结果?
- c - Linux下抓包时IP地址相同(C程序)
- java - 如何从 Eclipse 或其他方式调试 .bsh 文件
- mongodb - 如何从 mongodb 迁移到 gcp 数据存储
- macos - Safari 浏览器中的动作链失败
- .htaccess - 使用子文件夹重定向域删除斜线
- sql - 如何在sql中只将新行从一个表添加到另一个表
- python - 豁免网址有问题
- c# - SlideOverKit:“SlideMenuView”类型的值不能添加到“IList”类型的集合或字典中
- python - 根据熊猫数据框中的条件将单元格拆分/分解为多行