这是crsf解析说明:

这是一个TEST代码:

使用下面代码可以对接收到的数据进行解析
import struct
def parse_attitude(payload: bytes):
"""解析姿态(pitch roll yaw)单位 0.1°"""
pitch = struct.unpack("<h", payload[0:2])[0]
roll = struct.unpack("<h", payload[2:4])[0]
yaw = struct.unpack("<h", payload[4:6])[0]
print('hex: ', hex(pitch), hex(roll), hex(yaw))
print('int: ', int(pitch), int(roll), int(yaw))
return pitch, roll, yaw
def parse_attitude_deg(payload: bytes):
"""解析姿态(pitch roll yaw)单位 0.1°"""
pitch = struct.unpack("<h", payload[0:2])[0] / 10000 * 180 / 3.1415
roll = struct.unpack("<h", payload[2:4])[0] / 10000 * 180 / 3.1415
yaw = struct.unpack("<h", payload[4:6])[0] / 10000 * 180 / 3.1415
print('deg: ', pitch, roll, yaw)
return pitch, roll, yaw
hex_str = ["392eec655a85", "b77aad1e53e1"]
for s in hex_str:
print("-"*20)
print('origin str: ', s)
payload = bytes.fromhex(s)
parse_attitude(payload)
parse_attitude_deg(payload)
origin str: 392eec655a85这是attitude的pyload,总共6字节,2个字节一个摇杆为,转换成16进制为hex: 0x2e39 0x65ec -0x7aa6
上面运行后的结果:

623

被折叠的 条评论
为什么被折叠?



