MAVLink食用说明——安装
MAVLink的协议生成器
<!-- 修改 version 为整数 -->
<version>1</version>
<!-- 修改 dialect 为整数 -->
<dialect>1</dialect>
这两个部分都必须是数字 INT类型
这里有一个坑,注释里不可有中文
<?xml version="1.0"?> <mavlink> <!-- 修改 version 为整数 --> <version>1</version> <!-- 修改 dialect 为整数 --> <dialect>1</dialect> <!-- 其他消息定义保持不变 --> <messages> <message id="250" name="HEARTBEAT_WITH_STRING"> <description>Heartbeat message with a string</description> <!-- Heartbeat related fields --> <field type="uint8_t" name="type">Type of the MAV (quadrotor, helicopter, etc.)</field> <field type="uint8_t" name="autopilot">Autopilot type</field> <field type="uint8_t" name="base_mode">System mode bitfield</field> <field type="uint32_t" name="custom_mode">A bitfield for use for autopilot-specific flags</field> <field type="uint8_t" name="system_status">System status flag</field> <field type="uint8_t" name="mavlink_version">MAVLink version</field> <!-- String field --> <field type="char[16]" name="custom_string">Custom string (max 16 bytes)</field> </message> </messages> </mavlink>
这样写是不行的
首先heartbeat是基础包 如果不希望自己从头实现协议的话 不要创建heartbeat包
第二要include 最少include一个minimal
不然会有dont have MAV_HELICOPTER之类的报错
这样才是最小化的最简化payload
<?xml version="1.0"?> <mavlink> <include>minimal.xml</include> <version>3</version> <messages> <message id="010" name="PayLoad"> <description>Test all field types</description> <field type="char[17]" name="s">string</field> </message> </messages> </mavlink>

自定义方言要放到这个路径中,再去使用mavgen生成协议
最少要include一个minimal 这样才会匹配
不要轻易用waitheartbeat 会卡住
仍然是
[LinkName].mav.[MessageName]_send (param)
形式 mav不变
def start(self, prefs): masterlink = mavutil.mavlink_connection("COM3", baud=115200) current_dialect = mavutil.current_dialect print(f"当前使用的 MAVLink 方言是: {current_dialect}") library_name = 'pymavlink' spec = importlib.util.find_spec(library_name) library_path = os.path.dirname(spec.origin) print(f"{library_name} 库的安装路径是: {library_path}") aaa = 'aaa' masterlink.mav.payload_send(aaa.encode('utf-8')) bpy.app.timers.register(self.mode_check, persistent=True) return True
在这里我是使用的minnal协议后面填东西实现的
<messages> <message id="0" name="HEARTBEAT"> <description>The heartbeat message shows that a system or component is present and responding. The type and autopilot fields (along with the message component id), allow the receiving system to treat further messages from this system appropriately (e.g. by laying out the user interface based on the autopilot). This microservice is documented at https://mavlink.io/en/services/heartbeat.html</description> <field type="uint8_t" name="type" enum="MAV_TYPE">Vehicle or component type. For a flight controller component the vehicle type (quadrotor, helicopter, etc.). For other components the component type (e.g. camera, gimbal, etc.). This should be used in preference to component id for identifying the component type.</field> <field type="uint8_t" name="autopilot" enum="MAV_AUTOPILOT">Autopilot type / class. Use MAV_AUTOPILOT_INVALID for components that are not flight controllers.</field> <field type="uint8_t" name="base_mode" enum="MAV_MODE_FLAG" display="bitmask">System mode bitmap.</field> <field type="uint32_t" name="custom_mode">A bitfield for use for autopilot-specific flags</field> <field type="uint8_t" name="system_status" enum="MAV_STATE">System status flag.</field> <field type="uint8_t_mavlink_version" name="mavlink_version">MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version</field> </message> <message id="300" name="PROTOCOL_VERSION"> <wip/> <!-- This message is work-in-progress and it can therefore change. It should NOT be used in stable production environments. --> <description>Version and capability of protocol version. This message can be requested with MAV_CMD_REQUEST_MESSAGE and is used as part of the handshaking to establish which MAVLink version should be used on the network. Every node should respond to a request for PROTOCOL_VERSION to enable the handshaking. Library implementers should consider adding this into the default decoding state machine to allow the protocol core to respond directly.</description> <field type="uint16_t" name="version">Currently active MAVLink version number * 100: v1.0 is 100, v2.0 is 200, etc.</field> <field type="uint16_t" name="min_version">Minimum MAVLink version supported</field> <field type="uint16_t" name="max_version">Maximum MAVLink version supported (set to the same value as version by default)</field> <field type="uint8_t[8]" name="spec_version_hash">The first 8 bytes (not characters printed in hex!) of the git hash.</field> <field type="uint8_t[8]" name="library_version_hash">The first 8 bytes (not characters printed in hex!) of the git hash.</field> </message> <message id="100" name="PayLoad"> <description>Test all field types</description> <field type="char[16]" name="s">string</field> </message> </messages> </mavlink>
所以就没有额外增加方言,发送前要encode一下
然后由于协议过于简化,会报没有GPS_RAW什么的错误,所以165行注释掉一些和GPS RAW相关的东西
浙公网安备 33010602011771号