12 from pymavlink
import mavutil
14 from mavros_msgs.msg
import Mavlink
15 from std_msgs.msg
import Header
20 Re-builds the MAVLink byte stream from mavros_msgs/Mavlink messages. 22 Support both v1.0 and v2.0. 24 payload_octets =
len(msg.payload64)
25 if payload_octets < msg.len / 8:
26 raise ValueError(
"Specified payload length is bigger than actual payload64")
28 if msg.magic == Mavlink.MAVLINK_V10:
32 '<BBBBBB%dQ' % payload_octets,
33 msg.magic, msg.len, msg.seq, msg.sysid, msg.compid, msg.msgid,
36 msg_len = 10 + msg.len
39 '<BBBBBBBBBB%dQ' % payload_octets,
40 msg.magic, msg.len, msg.incompat_flags, msg.compat_flags, msg.seq,
41 msg.sysid, msg.compid,
42 msg.msgid & 0xff, (msg.msgid >> 8) & 0xff, (msg.msgid >> 16) & 0xff,
45 if payload_octets != msg.len / 8:
47 msgdata = msgdata[:msg_len]
50 msgdata += struct.pack(
'<H', msg.checksum)
52 if msg.magic == Mavlink.MAVLINK_V20:
53 msgdata += bytearray(msg.signature)
60 Convert payload bytes to Mavlink.payload64 62 payload_bytes = bytearray(payload_bytes)
63 payload_len =
len(payload_bytes)
64 payload_octets = payload_len / 8
65 if payload_len % 8 > 0:
67 payload_bytes += b
'\0' * (8 - payload_len % 8)
69 return struct.unpack(
'<%dQ' % payload_octets, payload_bytes)
74 Convert pymavlink message to Mavlink.msg 76 Currently supports MAVLink v1.0 only. 79 header = Header(stamp=stamp)
81 header = Header(stamp=rospy.get_rostime())
83 if mavutil.mavlink20():
85 if mavmsg.get_signed():
86 rospy.logerr(
"Signed message can't be converted to rosmsg.")
88 hdr = mavmsg.get_header()
91 framing_status=Mavlink.FRAMING_OK,
92 magic=Mavlink.MAVLINK_V20,
94 incompat_flags=hdr.incompat_flags,
95 compat_flags=hdr.compat_flags,
97 compid=hdr.srcComponent,
99 checksum=mavmsg.get_crc(),
107 framing_status=Mavlink.FRAMING_OK,
108 magic=Mavlink.MAVLINK_V10,
109 len=
len(mavmsg.get_payload()),
110 seq=mavmsg.get_seq(),
111 sysid=mavmsg.get_srcSystem(),
112 compid=mavmsg.get_srcComponent(),
113 msgid=mavmsg.get_msgId(),
114 checksum=mavmsg.get_crc(),
def convert_to_payload64(payload_bytes)
def convert_to_rosmsg(mavmsg, stamp=None)
def convert_to_bytes(msg)