我可以使用我在 pymavlink文档中找到的以下代码来旋转 typhoon480 的云台。
connection = mavutil.mavlink_connection('udpin:0.0.0.0:14540')
connection.wait_heartbeat()
connection.mav.command_long_send(connection.target_system, connection.target_component, mavutil.mavlink.MAV_CMD_DO_MOUNT_CONTROL, 1, pitch, roll, yaw, 0, 0, 0, mavutil.mavlink.MAV_MOUNT_MODE_MAVLINK_TARGETING)
connection.close()
但是,我正在开发一个基于 ROS 的项目,并且正在从 ROS 启动文件设置 UDP 连接,如下所示:
<arg name="fcu_url" default="udp-b://:14540@14548"/>
所以我确实需要从 python 代码建立一个 UDP 连接。我正在创建这样的心跳连接,并尝试将 mavlink 消息作为 ROS 消息发送,如下所示:
hb_mav_msg = mavutil.mavlink.MAVLink_heartbeat_message(mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER, 0, 0, 0, 0, 0)
gimbal_mav_msg=mavutil.mavlink.mav.command_long_send(mavutil.mavlink.target_system, mavutil.mavlink.target_component, mavutil.mavlink.MAV_CMD_DO_MOUNT_CONTROL, 1, pitch, roll, yaw, 0, 0, 0, mavutil.mavlink.MAV_MOUNT_MODE_MAVLINK_TARGETING)
gimbal_ros_msg = mavlink.convert_to_rosmsg(gimbal_mav_msg)
pub.publish(gimbal_ros_msg)
它给出了以下错误:
AttributeError: module 'pymavlink.dialects.v10.ardupilotmega' has no attribute 'mav'