2036.6.10小更新
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import time
|
||||
from pymavlink import mavutil
|
||||
|
||||
# 根据你的实际 UDP 配置修改
|
||||
# 如果飞控是作为 UDP 服务端(监听),则 Python 应作为客户端连接:
|
||||
# connection_string = "udpout:飞控IP:14550"
|
||||
# 如果飞控是作为 UDP 客户端(主动连接 Python),则 Python 应作为服务端监听:
|
||||
connection_string = "udpin:127.0.0.1:14550"
|
||||
|
||||
master = mavutil.mavlink_connection(connection_string)
|
||||
|
||||
print("等待飞控心跳包...")
|
||||
try:
|
||||
master.wait_heartbeat(timeout=5)
|
||||
print(f"收到心跳,系统 ID: {master.target_system}, 组件 ID: {master.target_component}")
|
||||
except:
|
||||
print("超时:未收到飞控心跳包,请检查 IP 和端口配置以及飞控端是否在发送心跳")
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
"udp_port": 9999
|
||||
},
|
||||
"flight_control": {
|
||||
"connection_string": "udpout:127.0.0.1:14550",
|
||||
"connection_string": "AMA1",
|
||||
"baud_rate": 57600
|
||||
},
|
||||
"fc_info":{
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class PID:
|
||||
|
||||
|
||||
class UAVController:
|
||||
def __init__(self, port='/dev/ttyUSB0', baud=57600):
|
||||
def __init__(self, port='/dev/ttyAMA1', baud=57600):
|
||||
"""
|
||||
初始化与飞控的 MAVLink 串口连接
|
||||
port:串口地址
|
||||
|
||||
@@ -5,7 +5,7 @@ from pymavlink import mavutil
|
||||
|
||||
|
||||
class DroneController:
|
||||
def __init__(self, connection_string='udpout:127.0.0.1:14550', baud=115200):
|
||||
def __init__(self, connection_string='/dev/ttyAMA1', baud=115200):
|
||||
self.connection_string = connection_string
|
||||
self.baud = baud
|
||||
self.master = None
|
||||
@@ -57,8 +57,7 @@ class DroneController:
|
||||
"""初始化 MAVLink 串口连接,并等待首个心跳包"""
|
||||
try:
|
||||
print(f"正在尝试连接飞控 ({self.connection_string})...")
|
||||
# 当使用udp时网络不再重要
|
||||
self.master = mavutil.mavlink_connection(self.connection_string)
|
||||
self.master = mavutil.mavlink_connection(self.connection_string, baud=self.baud)
|
||||
self.master.wait_heartbeat(timeout=5)
|
||||
self.is_connected = True
|
||||
self.last_heartbeat_time = time.time()
|
||||
|
||||
Reference in New Issue
Block a user