繁体   English   中英

使用pymavlink库接收和发送mavlink消息

[英]receiving and sending mavlink messages using pymavlink library

我在Python中创建了QGC(地面控制站)和车辆之间的代理。 这是代码:

gcs_conn = mavutil.mavlink_connection('tcpin:localhost:15795')
gcs_conn.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" %(gcs_conn.target_system, gcs_conn.target_system))
vehicle = mavutil.mavlink_connection('tcp:localhost:5760')
vehicle.wait_heartbeat() # recieving heartbeat from the vehicle
print("Heartbeat from system (system %u component %u)" %(vehicle.target_system, vehicle.target_system))
while True:
     gcs_msg = gcs_conn.recv_match()
     if gcs_msg == None:
         pass
     else:
         vehicle.mav.send(gcs_msg)
         print(gcs_msg)

     vcl_msg = vehicle.recv_match()
     if vcl_msg == None:
         pass
     else:
         gcs_conn.mav.send(vcl_msg)
         print(vcl_msg)

我需要接收来自QGC的消息,然后将它们转发到车辆,还需要接收来自车辆的消息,并将它们转发给QGC。 当我运行代码时,出现此错误

有谁可以帮助我吗?

如果在发送之前打印消息,您会发现尝试发送BAD_DATA消息类型时,消息总是失败。

因此,这应该可以解决(与vcl_msg相同):

if gcs_msg and gcs_msg.get_type() != 'BAD_DATA':
    vehicle.mav.send(gcs_msg)

PD:我注意到您没有将tcp指定为输入或输出,它默认为input 比意味着两个连接都是输入。 我建议将GCS连接设置为输出:

gcs_conn = mavutil.mavlink_connection('tcp:localhost:15795', input=False)

https://mavlink.io/en/mavgen_python/#connection_string

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM