3 mavlink python utility functions 5 Copyright Andrew Tridgell 2011 6 Released under GNU GPL version 3 or later 8 from __future__
import print_function
9 from builtins
import object
11 import socket, math, struct, time, os, fnmatch, array, sys, errno
13 from pymavlink
import mavexpression
25 UDP_MAX_PACKET_LEN = 65535
36 default_native =
False 42 if not 'MAVLINK_DIALECT' in os.environ:
43 os.environ[
'MAVLINK_DIALECT'] =
'ardupilotmega' 46 '''return True if using MAVLink 1.0 or later''' 47 return not 'MAVLINK09' in os.environ
50 '''return True if using MAVLink 2.0''' 51 return 'MAVLINK20' in os.environ
54 '''evaluation an expression''' 55 return mavexpression.evaluate_expression(expression, vars)
58 '''evaluation a conditional (boolean) statement''' 67 return ord(c)
if sys.version_info.major < 3
else c
70 '''represent a GPS coordinate''' 71 def __init__(self, lat, lng, alt=0, heading=0):
78 return "lat=%.6f,lon=%.6f,alt=%.1f" % (self.
lat, self.
lng, self.
alt)
81 '''set the MAVLink dialect to work with. 82 For example, set_dialect("ardupilotmega") 84 global mavlink, current_dialect
85 from .generator
import mavparse
86 if 'MAVLINK20' in os.environ:
87 wire_protocol = mavparse.PROTOCOL_2_0
88 modname =
"pymavlink.dialects.v20." + dialect
89 elif mavlink
is None or mavlink.WIRE_PROTOCOL_VERSION ==
"1.0" or not 'MAVLINK09' in os.environ:
90 wire_protocol = mavparse.PROTOCOL_1_0
91 modname =
"pymavlink.dialects.v10." + dialect
93 wire_protocol = mavparse.PROTOCOL_0_9
94 modname =
"pymavlink.dialects.v09." + dialect
97 mod = __import__(modname)
100 from .generator.mavgen
import mavgen_python_dialect
102 mod = __import__(modname)
103 components = modname.split(
'.')
104 for comp
in components[1:]:
105 mod = getattr(mod, comp)
106 current_dialect = dialect
113 '''state for a particular system id''' 122 if float(mavlink.WIRE_PROTOCOL_VERSION) >= 1:
123 self.
messages[
'HOME'] = mavlink.MAVLink_gps_raw_int_message(0,0,0,0,0,0,0,0,0,0)
124 mavlink.MAVLink_waypoint_message = mavlink.MAVLink_mission_item_message
126 self.
messages[
'HOME'] = mavlink.MAVLink_gps_raw_message(0,0,0,0,0,0,0,0,0)
129 '''state for a particular system id/component id pair''' 134 '''a generic mavlink port''' 135 def __init__(self, fd, address, source_system=255, source_component=0, notimestamps=False, input=True, use_native=default_native):
136 global mavfile_global
138 mavfile_global = self
184 @target_system.setter
194 @target_component.setter
204 eff_tuple = (self.
sysid, 1)
206 return getattr(self.
param_state[eff_tuple],
'params')
246 '''auto-switch mavlink protocol version''' 254 if not magic
in [ 85, 254, 253 ]:
262 os.environ[
'MAVLINK09'] =
'1' 266 os.environ[
'MAVLINK20'] =
'1' 271 (callback, callback_args, callback_kwargs) = (self.mav.callback,
272 self.mav.callback_args,
273 self.mav.callback_kwargs)
277 (self.mav.callback, self.mav.callback_args, self.mav.callback_kwargs) = (callback,
282 '''default recv method''' 283 raise RuntimeError(
'no recv() method supplied')
286 '''default close method''' 287 raise RuntimeError(
'no close() method supplied')
290 '''default write method''' 291 raise RuntimeError(
'no write() method supplied')
295 '''wait for up to timeout seconds for more data''' 297 time.sleep(min(timeout,0.5))
300 (rin, win, xin) = select.select([self.
fd], [], [], timeout)
306 '''default pre message call''' 310 '''enable/disable RTS/CTS if applicable''' 314 if msg.get_srcComponent() == mavlink.MAV_COMP_ID_GIMBAL:
316 if msg.type
in (mavlink.MAV_TYPE_GCS,
317 mavlink.MAV_TYPE_GIMBAL,
318 mavlink.MAV_TYPE_ADSB,
319 mavlink.MAV_TYPE_ONBOARD_CONTROLLER):
324 '''default post message call''' 325 if '_posted' in msg.__dict__:
328 msg._timestamp = time.time()
329 type = msg.get_type()
331 if 'usec' in msg.__dict__:
332 self.
uptime = msg.usec * 1.0e-6
333 if 'time_boot_ms' in msg.__dict__:
334 self.
uptime = msg.time_boot_ms * 1.0e-3
338 msg._timestamp = self.
uptime 342 src_system = msg.get_srcSystem()
343 src_component = msg.get_srcComponent()
344 src_tuple = (src_system, src_component)
346 radio_tuple = (ord(
'3'), ord(
'D'))
354 if not (src_tuple == radio_tuple
or msg.get_type() ==
'BAD_DATA'):
359 seq = (last_seq+1) % 256
361 if seq != seq2
and last_seq != -1:
362 diff = (seq2 - seq) % 256
372 self.
sysid = src_system
373 if float(mavlink.WIRE_PROTOCOL_VERSION) >= 1:
377 self.
sysid_state[self.
sysid].armed = (msg.base_mode & mavlink.MAV_MODE_FLAG_SAFETY_ARMED)
379 elif type ==
'PARAM_VALUE':
382 self.
param_state[src_tuple].params[msg.param_id] = msg.param_value
383 elif type ==
'SYS_STATUS' and mavlink.WIRE_PROTOCOL_VERSION ==
'0.9':
385 elif type ==
'GPS_RAW':
386 if self.
sysid_state[src_system].messages[
'HOME'].fix_type < 2:
387 self.
sysid_state[src_system].messages[
'HOME'] = msg
388 elif type ==
'GPS_RAW_INT':
389 if self.
sysid_state[src_system].messages[
'HOME'].fix_type < 3:
390 self.
sysid_state[src_system].messages[
'HOME'] = msg
394 if (msg.get_signed()
and 395 self.mav.signing.link_id == 0
and 396 msg.get_link_id() != 0
and 400 self.mav.signing.link_id = msg.get_link_id()
404 '''packet loss as a percentage''' 411 '''message receive routine''' 414 n = self.mav.bytes_needed()
420 self.logfile_raw.write(
str(s))
426 msg = self.mav.parse_char(s)
428 if self.
logfile and msg.get_type() !=
'BAD_DATA' :
429 usec =
int(time.time() * 1.0e6) & ~3
430 self.logfile.write(
str(struct.pack(
'>Q', usec) + msg.get_msgbuf()))
439 def recv_match(self, condition=None, type=None, blocking=False, timeout=None):
440 '''recv the next MAVLink message that matches the given condition 441 type can be a string or a list of strings''' 442 if type
is not None and not isinstance(type, list)
and not isinstance(type, set):
444 start_time = time.time()
446 if timeout
is not None:
450 if start_time + timeout < time.time():
463 if type
is not None and not m.get_type()
in type:
470 '''check if a condition is true''' 474 '''return True if using MAVLink 1.0 or later''' 478 '''return True if using MAVLink 2.0 or later''' 482 '''start logging to the given logfile, with timestamps''' 483 self.
logfile = open(logfile, mode=mode)
486 '''start logging raw bytes to the given logfile, without timestamps''' 490 '''wait for a heartbeat so we know the target system IDs''' 491 return self.
recv_match(type=
'HEARTBEAT', blocking=blocking, timeout=timeout)
494 '''initiate fetch of all parameters''' 502 '''initiate fetch of one parameter''' 507 if sys.version_info.major >= 3
and not isinstance(name, bytes):
508 name = bytes(name,
'ascii')
512 '''return the time since the last message of type mtype was received''' 515 return time.time() - self.
messages[mtype]._timestamp
518 '''wrapper for parameter set''' 520 if parm_type
is None:
521 parm_type = mavlink.MAVLINK_TYPE_FLOAT
523 parm_name.encode(
'utf8'), parm_value, parm_type)
526 parm_name.encode(
'utf8'), parm_value)
529 '''wrapper for waypoint_request_list_send''' 536 '''wrapper for waypoint_clear_all_send''' 543 '''wrapper for waypoint_request_send''' 550 '''wrapper for waypoint_set_current_send''' 557 '''return current waypoint''' 559 m = self.
recv_match(type=
'MISSION_CURRENT', blocking=
True)
561 m = self.
recv_match(type=
'WAYPOINT_CURRENT', blocking=
True)
565 '''wrapper for waypoint_count_send''' 573 Enables/ disables MAV_MODE_FLAG 574 @param flag The mode flag, 575 see MAV_MODE_FLAG enum 576 @param enable Enable the flag, (True/False) 585 mavlink.MAV_CMD_DO_SET_MODE, 0,
589 print(
"Set mode flag not supported")
592 '''enter auto mode''' 595 mavlink.MAV_CMD_MISSION_START, 0, 0, 0, 0, 0, 0, 0, 0)
597 MAV_ACTION_SET_AUTO = 13
601 '''return dictionary mapping mode names to numbers, or None if unknown''' 603 mav_autopilot = self.
field(
'HEARTBEAT',
'autopilot',
None)
604 if mav_autopilot == mavlink.MAV_AUTOPILOT_PX4:
609 if mav_type
in [mavlink.MAV_TYPE_QUADROTOR,
610 mavlink.MAV_TYPE_HELICOPTER,
611 mavlink.MAV_TYPE_HEXAROTOR,
612 mavlink.MAV_TYPE_OCTOROTOR,
613 mavlink.MAV_TYPE_DODECAROTOR,
614 mavlink.MAV_TYPE_COAXIAL,
615 mavlink.MAV_TYPE_TRICOPTER]:
616 map = mode_mapping_acm
617 if mav_type == mavlink.MAV_TYPE_FIXED_WING:
618 map = mode_mapping_apm
619 if mav_type == mavlink.MAV_TYPE_GROUND_ROVER:
620 map = mode_mapping_rover
621 if mav_type == mavlink.MAV_TYPE_SURFACE_BOAT:
622 map = mode_mapping_rover
623 if mav_type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
624 map = mode_mapping_tracker
625 if mav_type == mavlink.MAV_TYPE_SUBMARINE:
626 map = mode_mapping_sub
629 inv_map = dict((a, b)
for (b, a)
in map.items())
633 '''enter arbitrary mode''' 634 if isinstance(mode, str):
636 if mode_map
is None or mode
not in mode_map:
637 print(
"Unknown mode '%s'" % mode)
639 mode = mode_map[mode]
642 mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
646 '''enter arbitrary mode''' 647 if isinstance(mode, str):
649 if mode_map
is None or mode
not in mode_map:
650 print(
"Unknown mode '%s'" % mode)
653 mode, custom_mode, custom_sub_mode = px4_map[mode]
655 mavlink.MAV_CMD_DO_SET_MODE, 0, mode, custom_mode, custom_sub_mode, 0, 0, 0, 0)
657 def set_mode(self, mode, custom_mode = 0, custom_sub_mode = 0):
658 '''set arbitrary flight mode''' 659 mav_autopilot = self.
field(
'HEARTBEAT',
'autopilot',
None)
660 if mav_autopilot == mavlink.MAV_AUTOPILOT_PX4:
669 mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH, 0, 0, 0, 0, 0, 0, 0, 0)
671 MAV_ACTION_RETURN = 3
675 '''enter MANUAL mode''' 678 mavlink.MAV_CMD_DO_SET_MODE, 0,
679 mavlink.MAV_MODE_MANUAL_ARMED,
682 MAV_ACTION_SET_MANUAL = 12
686 '''enter FBWA mode''' 689 mavlink.MAV_CMD_DO_SET_MODE, 0,
690 mavlink.MAV_MODE_STABILIZE_ARMED,
693 print(
"Forcing FBWA not supported")
696 '''enter LOITER mode''' 699 mavlink.MAV_CMD_NAV_LOITER_UNLIM, 0, 0, 0, 0, 0, 0, 0, 0)
701 MAV_ACTION_LOITER = 27
705 '''set a servo value''' 707 mavlink.MAV_CMD_DO_SET_SERVO, 0,
713 '''Set relay_pin to value of state''' 715 self.mav.command_long_send(
718 mavlink.MAV_CMD_DO_SET_RELAY,
728 print(
"Setting relays not supported.")
731 '''calibrate accels (1D version)''' 733 mavlink.MAV_CMD_PREFLIGHT_CALIBRATION, 0,
737 '''calibrate pressure''' 740 mavlink.MAV_CMD_PREFLIGHT_CALIBRATION, 0,
743 MAV_ACTION_CALIBRATE_PRESSURE = 20
747 '''reboot the autopilot''' 749 if hold_in_bootloader:
754 mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
755 param1, 0, 0, 0, 0, 0, 0)
759 mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
763 self.
recv_match(type=
'VFR_HUD', blocking=
True)
765 self.
recv_match(type=
'GPS_RAW_INT', blocking=
True,
766 condition=
'GPS_RAW_INT.fix_type>=3 and GPS_RAW_INT.lat != 0')
768 self.
recv_match(type=
'GPS_RAW', blocking=
True,
769 condition=
'GPS_RAW.fix_type>=2 and GPS_RAW.lat != 0')
772 '''return current location''' 775 self.
recv_match(type=
'VFR_HUD', blocking=
True)
776 self.
recv_match(type=
'GLOBAL_POSITION_INT', blocking=
True)
778 alt = self.
messages[
'GLOBAL_POSITION_INT'].relative_alt*0.001
782 self.
messages[
'GPS_RAW_INT'].lon*1.0e-7,
787 '''arm motors (arducopter only)''' 789 self.mav.command_long_send(
792 mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
803 '''calibrate pressure''' 805 self.mav.command_long_send(
808 mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
819 '''return true if motors armed''' 823 '''wait for motors to be armed''' 830 '''wait for motors to be disarmed''' 837 def field(self, type, field, default=None):
838 '''convenient function for returning an arbitrary MAVLink 839 field with a default''' 842 return getattr(self.
messages[type], field, default)
844 def param(self, name, default=None):
845 '''convenient function for returning an arbitrary MAVLink 846 parameter with a default''' 847 if not name
in self.
params:
851 def setup_signing(self, secret_key, sign_outgoing=True, allow_unsigned_callback=None, initial_timestamp=None, link_id=None):
852 '''setup for MAVLink2 signing''' 853 self.mav.signing.secret_key = secret_key
854 self.mav.signing.sign_outgoing = sign_outgoing
855 self.mav.signing.allow_unsigned_callback = allow_unsigned_callback
858 global global_link_id
859 link_id = global_link_id
860 global_link_id = min(global_link_id + 1, 255)
861 self.mav.signing.link_id = link_id
862 if initial_timestamp
is None:
864 epoch_offset = 1420070400
865 now = max(time.time(), epoch_offset)
866 initial_timestamp = now - epoch_offset
867 initial_timestamp =
int(initial_timestamp * 100 * 1000)
869 self.mav.signing.timestamp = initial_timestamp
872 '''disable MAVLink2 signing''' 873 self.mav.signing.secret_key =
None 874 self.mav.signing.sign_outgoing =
False 875 self.mav.signing.allow_unsigned_callback =
None 876 self.mav.signing.link_id = 0
877 self.mav.signing.timestamp = 0
880 '''set the clone on exec flag on a file descriptor. Ignore exceptions''' 883 flags = fcntl.fcntl(fd, fcntl.F_GETFD)
884 flags |= fcntl.FD_CLOEXEC
885 fcntl.fcntl(fd, fcntl.F_SETFD, flags)
895 raise Exception(
"write always fails")
901 class mavserial(mavfile):
902 '''a serial mavlink port''' 903 def __init__(self, device, baud=115200, autoreconnect=False, source_system=255, source_component=0, use_native=default_native, force_connected=False):
905 if ',' in device
and not os.path.exists(device):
906 device, baud = device.split(
',')
916 dsrdtr=
False, rtscts=
False, xonxoff=
False)
917 except serial.SerialException
as e:
918 if not force_connected:
923 fd = self.port.fileno()
928 mavfile.__init__(self, fd, device, source_system=source_system, source_component=source_component, use_native=use_native)
932 '''enable/disable RTS/CTS if applicable''' 934 self.port.setRtsCts(enable)
936 self.port.rtscts = enable
942 self.port.setBaudrate(baudrate)
945 self.port.baudrate = baudrate
952 n = self.mav.bytes_needed()
954 waiting = self.port.inWaiting()
957 ret = self.port.read(n)
962 return self.port.write(bytes(buf))
965 print(
"Device %s is dead" % self.
device)
975 newport = serial.Serial(self.
device, self.
baud, timeout=0,
976 dsrdtr=
False, rtscts=
False, xonxoff=
False)
977 except serial.SerialException
as e:
984 print(
"Device %s reopened OK" % self.
device)
987 self.
fd = self.port.fileno()
999 '''a UDP mavlink socket''' 1000 def __init__(self, device, input=True, broadcast=False, source_system=255, source_component=0, use_native=default_native):
1001 a = device.split(
':')
1003 print(
"UDP ports must be specified as host:port")
1005 self.
port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1009 self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1010 self.port.bind((a[0],
int(a[1])))
1014 self.port.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
1017 self.port.setblocking(0)
1020 mavfile.__init__(self, self.port.fileno(), device, source_system=source_system, source_component=source_component, input=input, use_native=use_native)
1027 data, new_addr = self.port.recvfrom(UDP_MAX_PACKET_LEN)
1028 except socket.error
as e:
1029 if e.errno
in [ errno.EAGAIN, errno.EWOULDBLOCK, errno.ECONNREFUSED ]:
1052 except socket.error:
1056 '''message receive routine for UDP link''' 1063 m = self.mav.parse_char(s)
1070 '''a UDP multicast mavlink socket''' 1071 def __init__(self, device, broadcast=False, source_system=255, source_component=0, use_native=default_native):
1072 a = device.split(
':')
1073 mcast_ip =
"239.255.145.50" 1075 if len(a) == 1
and len(a[0]) > 0:
1076 mcast_port =
int(a[0])
1079 mcast_port =
int(a[1])
1084 self.
port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
1085 self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1086 self.port.bind((mcast_ip, mcast_port))
1087 mreq = struct.pack(
"4sl", socket.inet_aton(mcast_ip), socket.INADDR_ANY)
1088 self.port.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
1089 self.port.setblocking(0)
1093 self.
port_out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1094 self.port_out.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1095 self.port_out.setblocking(0)
1096 self.port_out.connect((mcast_ip, mcast_port))
1100 mavfile.__init__(self, self.port.fileno(), device,
1101 source_system=source_system, source_component=source_component,
1102 input=
False, use_native=use_native)
1106 self.port_out.close()
1110 data, new_addr = self.port.recvfrom(UDP_MAX_PACKET_LEN)
1113 (myaddr,self.
myport) = self.port_out.getsockname()
1116 except socket.error
as e:
1117 if e.errno
in [ errno.EAGAIN, errno.EWOULDBLOCK, errno.ECONNREFUSED ]:
1120 if self.
myport == new_addr[1]:
1127 self.port_out.send(buf)
1128 except socket.error
as e:
1132 '''message receive routine for UDP link''' 1139 m = self.mav.parse_char(s)
1147 '''a TCP mavlink socket''' 1150 autoreconnect=
False,
1154 use_native=default_native):
1155 a = device.split(
':')
1157 print(
"TCP ports must be specified as host:port")
1165 mavfile.__init__(self, self.port.fileno(),
"tcp:" + device, source_system=source_system, source_component=source_component, use_native=use_native)
1168 self.
port = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1177 except Exception
as e:
1180 print(e,
"sleeping")
1182 self.port.setblocking(0)
1184 self.port.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
1191 n = self.mav.bytes_needed()
1193 data = self.port.recv(n)
1194 except socket.error
as e:
1195 if e.errno
in [ errno.EAGAIN, errno.EWOULDBLOCK ]:
1200 print(
"EOF on TCP socket")
1202 print(
"Attempting reconnect")
1211 except socket.error:
1216 '''a TCP input mavlink socket''' 1217 def __init__(self, device, source_system=255, source_component=0, retries=3, use_native=default_native):
1218 a = device.split(
':')
1220 print(
"TCP ports must be specified as host:port")
1222 self.
listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1225 self.listen.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1226 self.listen.listen(1)
1227 self.listen.setblocking(0)
1229 self.listen.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
1230 mavfile.__init__(self, self.listen.fileno(),
"tcpin:" + device, source_system=source_system, source_component=source_component, use_native=use_native)
1239 (self.
port, addr) = self.listen.accept()
1242 self.port.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
1243 self.port.setblocking(0)
1245 self.
fd = self.port.fileno()
1248 n = self.mav.bytes_needed()
1250 data = self.port.recv(n)
1251 except socket.error
as e:
1252 if e.errno
in [ errno.EAGAIN, errno.EWOULDBLOCK ]:
1256 self.
fd = self.listen.fileno()
1261 if self.
port is None:
1265 except socket.error
as e:
1266 if e.errno
in [ errno.EPIPE ]:
1269 self.
fd = self.listen.fileno()
1274 '''a MAVLink logfile reader/writer''' 1275 def __init__(self, filename, planner_format=None,
1276 write=
False, append=
False,
1277 robust_parsing=
True, notimestamps=
False, source_system=255, source_component=0, use_native=default_native):
1289 self.
f = open(filename, mode)
1292 mavfile.__init__(self,
None, filename, source_system=source_system, source_component=source_component, notimestamps=notimestamps, use_native=use_native)
1307 n = self.mav.bytes_needed()
1308 return self.f.read(n)
1314 '''scan forward looking in a tlog for a timestamp in a reasonable range''' 1316 (tusec,) = struct.unpack(
'>Q', tbuf)
1328 '''read timestamp if needed''' 1335 tbuf = self.f.read(21)
1336 if len(tbuf) != 21
or tbuf[0] !=
'-' or tbuf[20] !=
':':
1337 raise RuntimeError(
'bad planner timestamp %s' % tbuf)
1340 t -= 719163 * 24 * 60 * 60
1343 tbuf = self.f.read(8)
1346 (tusec,) = struct.unpack(
'>Q', tbuf)
1349 self._last_message.get_type() ==
"BAD_DATA" and 1352 self.
_link = tusec & 0x3
1356 '''add timestamp to message''' 1363 if msg.get_type() !=
"BAD_DATA":
1365 msg._link = self.
_link 1369 '''a MAVLink log file accessed via mmap. Used for fast read-only 1370 access with low memory overhead where particular message types are wanted''' 1372 import platform, mmap
1373 mavlogfile.__init__(self, filename)
1377 if platform.system() ==
"Windows":
1380 self.
data_map = mmap.mmap(self.f.fileno(), self.
data_len, mmap.MAP_PRIVATE, mmap.PROT_READ)
1386 '''rewind to start of log''' 1393 '''rewind to start of log''' 1397 '''initialise arrays for fast recv_match()''' 1424 if marker == MARKER_V1:
1427 elif marker == MARKER_V2:
1431 if incompat_flags & mavlink.MAVLINK_IFLAG_SIGNED:
1432 mlen += mavlink.MAVLINK_SIGNATURE_BLOCK_LEN
1435 if not mtype
in mavlink.mavlink_map:
1440 msg = mavlink.mavlink_map[mtype]
1447 self.
offsets[mtype].append(ofs)
1451 new_pct = (100 * ofs) // self.
data_len 1452 if progress_callback
is not None and new_pct != pct:
1453 progress_callback(new_pct)
1456 for mtype
in self.
counts:
1462 '''skip fwd to next msg matching given type set''' 1466 type.update(set([
'HEARTBEAT',
'PARAM_VALUE']))
1473 self.indexes.append(0)
1481 if ofs < smallest_offset:
1482 smallest_offset = ofs
1484 if smallest_index >= 0:
1485 self.
indexes[smallest_index] += 1
1486 self.
offset = smallest_offset
1487 self.f.seek(smallest_offset)
1489 def recv_match(self, condition=None, type=None, blocking=False, timeout=None):
1490 '''recv the next message that matches the given condition 1491 type can be a string or a list of strings''' 1492 if type
is not None:
1493 if isinstance(type, str):
1495 elif isinstance(type, list):
1498 if type
is not None:
1511 if type
is not None and not m.get_type()
in type:
1518 '''return an array of tuples for all flightmodes in log. Tuple is (modestring, t0, t1)''' 1524 types = set([
'HEARTBEAT'])
1529 tstamp = m._timestamp
1535 self._flightmodes.append((self.
flightmode, tstamp,
None))
1537 if tstamp
is not None:
1545 '''a MAVLink child processes reader/writer''' 1546 def __init__(self, filename, source_system=255, source_component=0, use_native=default_native):
1547 from subprocess
import Popen, PIPE
1551 self.
child = Popen(filename, shell=
False, stdout=PIPE, stdin=PIPE, bufsize=0)
1552 self.
fd = self.child.stdout.fileno()
1554 fl = fcntl.fcntl(self.
fd, fcntl.F_GETFL)
1555 fcntl.fcntl(self.
fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
1557 fl = fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_GETFL)
1558 fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)
1560 mavfile.__init__(self, self.
fd, filename, source_system=source_system, source_component=source_component, use_native=use_native)
1567 x = self.child.stdout.read(1)
1573 self.child.stdin.write(buf)
1577 planner_format=
None, write=
False, append=
False,
1578 robust_parsing=
True, notimestamps=
False, input=
True,
1579 dialect=
None, autoreconnect=
False, zero_time_base=
False,
1580 retries=3, use_native=default_native,
1581 force_connected=
False, progress_callback=
None):
1582 '''open a serial, UDP, TCP or file mavlink connection''' 1583 global mavfile_global
1587 autoreconnect =
True 1589 if dialect
is not None:
1591 if device.startswith(
'tcp:'):
1592 return mavtcp(device[4:],
1593 autoreconnect=autoreconnect,
1594 source_system=source_system,
1595 source_component=source_component,
1597 use_native=use_native)
1598 if device.startswith(
'tcpin:'):
1599 return mavtcpin(device[6:], source_system=source_system, source_component=source_component, retries=retries, use_native=use_native)
1600 if device.startswith(
'udpin:'):
1601 return mavudp(device[6:], input=
True, source_system=source_system, source_component=source_component, use_native=use_native)
1602 if device.startswith(
'udpout:'):
1603 return mavudp(device[7:], input=
False, source_system=source_system, source_component=source_component, use_native=use_native)
1604 if device.startswith(
'udpbcast:'):
1605 return mavudp(device[9:], input=
False, source_system=source_system, source_component=source_component, use_native=use_native, broadcast=
True)
1607 if device.startswith(
'udp:'):
1608 return mavudp(device[4:], input=input, source_system=source_system, source_component=source_component, use_native=use_native)
1609 if device.startswith(
'mcast:'):
1610 return mavmcast(device[6:], source_system=source_system, source_component=source_component, use_native=use_native)
1612 if device.lower().endswith(
'.bin')
or device.lower().endswith(
'.px4log'):
1614 from pymavlink
import DFReader
1619 if device.endswith(
'.log'):
1621 from pymavlink
import DFReader
1622 if DFReader.DFReader_is_text_log(device):
1628 logsuffixes = [
'mavlink',
'log',
'raw',
'tlog' ]
1629 suffix = device.split(
'.')[-1].lower()
1630 if device.find(
':') != -1
and not suffix
in logsuffixes:
1631 return mavudp(device, source_system=source_system, source_component=source_component, input=input, use_native=use_native)
1632 if os.path.isfile(device):
1633 if device.endswith(
".elf")
or device.find(
"/bin/") != -1:
1634 print(
"executing '%s'" % device)
1635 return mavchildexec(device, source_system=source_system, source_component=source_component, use_native=use_native)
1636 elif not write
and not append
and not notimestamps:
1637 return mavmmaplog(device, progress_callback=progress_callback)
1639 return mavlogfile(device, planner_format=planner_format, write=write,
1640 append=append, robust_parsing=robust_parsing, notimestamps=notimestamps,
1641 source_system=source_system, source_component=source_component, use_native=use_native)
1644 source_system=source_system,
1645 source_component=source_component,
1646 autoreconnect=autoreconnect,
1647 use_native=use_native,
1648 force_connected=force_connected)
1651 '''a class for fixed frequency events''' 1657 '''force immediate triggering''' 1661 '''return True if we should trigger now''' 1665 print(
"Warning, time moved backwards. Restarting timer.")
1675 from curses
import ascii
1681 '''see if a character is printable''' 1684 return ascii.isprint(c)
1685 if isinstance(c, int):
1689 return ic >= 32
and ic <= 126
1692 '''see if a string is all printable''' 1694 if not is_printable(c)
and not c
in [
'\r',
'\n',
'\t']:
1699 '''auto-detected serial port''' 1700 def __init__(self, device, description=None, hwid=None):
1709 if self.
hwid is not None:
1710 ret +=
" : " + self.
hwid 1714 '''try to auto-detect serial ports on win32''' 1716 from serial.tools.list_ports_windows
import comports
1717 list = sorted(comports())
1722 for port, description, hwid
in list:
1724 p =
SerialPort(port, description=description, hwid=hwid)
1725 for preferred
in preferred_list:
1726 if fnmatch.fnmatch(description, preferred)
or fnmatch.fnmatch(hwid, preferred):
1742 '''try to auto-detect serial ports on unix''' 1744 glist = glob.glob(
'/dev/ttyS*') + glob.glob(
'/dev/ttyUSB*') + glob.glob(
'/dev/ttyACM*') + glob.glob(
'/dev/serial/by-id/*')
1750 for preferred
in preferred_list:
1751 if fnmatch.fnmatch(d, preferred):
1763 '''try to auto-detect serial port''' 1770 '''mode string for 0.9 protocol''' 1772 nav_mode = msg.nav_mode
1782 MAV_NAV_GROUNDED = 0
1785 MAV_NAV_WAYPOINT = 3
1787 MAV_NAV_RETURNING = 5
1792 cmode = (mode, nav_mode)
1794 (MAV_MODE_UNINIT, MAV_NAV_GROUNDED) :
"INITIALISING",
1795 (MAV_MODE_MANUAL, MAV_NAV_VECTOR) :
"MANUAL",
1796 (MAV_MODE_TEST3, MAV_NAV_VECTOR) :
"CIRCLE",
1797 (MAV_MODE_GUIDED, MAV_NAV_VECTOR) :
"GUIDED",
1798 (MAV_MODE_TEST1, MAV_NAV_VECTOR) :
"STABILIZE",
1799 (MAV_MODE_TEST2, MAV_NAV_LIFTOFF) :
"FBWA",
1800 (MAV_MODE_AUTO, MAV_NAV_WAYPOINT) :
"AUTO",
1801 (MAV_MODE_AUTO, MAV_NAV_RETURNING) :
"RTL",
1802 (MAV_MODE_AUTO, MAV_NAV_LOITER) :
"LOITER",
1803 (MAV_MODE_AUTO, MAV_NAV_LIFTOFF) :
"TAKEOFF",
1804 (MAV_MODE_AUTO, MAV_NAV_LANDING) :
"LANDING",
1805 (MAV_MODE_AUTO, MAV_NAV_HOLD) :
"LOITER",
1806 (MAV_MODE_GUIDED, MAV_NAV_VECTOR) :
"GUIDED",
1807 (MAV_MODE_GUIDED, MAV_NAV_WAYPOINT) :
"GUIDED",
1808 (100, MAV_NAV_VECTOR) :
"STABILIZE",
1809 (101, MAV_NAV_VECTOR) :
"ACRO",
1810 (102, MAV_NAV_VECTOR) :
"ALT_HOLD",
1811 (107, MAV_NAV_VECTOR) :
"CIRCLE",
1812 (109, MAV_NAV_VECTOR) :
"LAND",
1814 if cmode
in mapping:
1815 return mapping[cmode]
1816 return "Mode(%s,%s)" % cmode
1818 mode_mapping_apm = {
1833 16 :
'INITIALISING',
1841 mode_mapping_acm = {
1861 20 :
'GUIDED_NOGPS',
1866 mode_mapping_rover = {
1880 mode_mapping_tracker = {
1888 mode_mapping_sub = {
1905 mainstate_mapping_px4 = {
1916 10 :
'AUTO_TAKEOFF',
1918 12 :
'AUTO_FOLLOW_TARGET',
1922 return mainstate_mapping_px4.get(MainState,
"Unknown")
1926 PX4_CUSTOM_MAIN_MODE_MANUAL = 1
1927 PX4_CUSTOM_MAIN_MODE_ALTCTL = 2
1928 PX4_CUSTOM_MAIN_MODE_POSCTL = 3
1929 PX4_CUSTOM_MAIN_MODE_AUTO = 4
1930 PX4_CUSTOM_MAIN_MODE_ACRO = 5
1931 PX4_CUSTOM_MAIN_MODE_OFFBOARD = 6
1932 PX4_CUSTOM_MAIN_MODE_STABILIZED = 7
1933 PX4_CUSTOM_MAIN_MODE_RATTITUDE = 8
1935 PX4_CUSTOM_SUB_MODE_OFFBOARD = 0
1936 PX4_CUSTOM_SUB_MODE_AUTO_READY = 1
1937 PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF = 2
1938 PX4_CUSTOM_SUB_MODE_AUTO_LOITER = 3
1939 PX4_CUSTOM_SUB_MODE_AUTO_MISSION = 4
1940 PX4_CUSTOM_SUB_MODE_AUTO_RTL = 5
1941 PX4_CUSTOM_SUB_MODE_AUTO_LAND = 6
1942 PX4_CUSTOM_SUB_MODE_AUTO_RTGS = 7
1943 PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET = 8
1945 auto_mode_flags = mavlink.MAV_MODE_FLAG_AUTO_ENABLED \
1946 | mavlink.MAV_MODE_FLAG_STABILIZE_ENABLED \
1947 | mavlink.MAV_MODE_FLAG_GUIDED_ENABLED
1949 px4_map = {
"MANUAL": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_STABILIZE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_MANUAL, 0 ),
1950 "STABILIZED": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_STABILIZE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_STABILIZED, 0 ),
1951 "ACRO": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_ACRO, 0 ),
1952 "RATTITUDE": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_RATTITUDE, 0 ),
1953 "ALTCTL": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_STABILIZE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_ALTCTL, 0 ),
1954 "POSCTL": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | mavlink.MAV_MODE_FLAG_STABILIZE_ENABLED | mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED, PX4_CUSTOM_MAIN_MODE_POSCTL, 0 ),
1955 "LOITER": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_LOITER ),
1956 "MISSION": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_MISSION ),
1957 "RTL": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_RTL ),
1958 "LAND": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_LAND ),
1959 "RTGS": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_RTGS ),
1960 "FOLLOWME": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET ),
1961 "OFFBOARD": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_OFFBOARD, 0 ),
1962 "TAKEOFF": (mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED | auto_mode_flags, PX4_CUSTOM_MAIN_MODE_AUTO, PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF )}
1966 custom_main_mode = (custom_mode & 0xFF0000) >> 16
1967 custom_sub_mode = (custom_mode & 0xFF000000) >> 24
1969 if base_mode & mavlink.MAV_MODE_FLAG_MANUAL_INPUT_ENABLED != 0:
1970 if custom_main_mode == PX4_CUSTOM_MAIN_MODE_MANUAL:
1972 elif custom_main_mode == PX4_CUSTOM_MAIN_MODE_ACRO:
1974 elif custom_main_mode == PX4_CUSTOM_MAIN_MODE_RATTITUDE:
1976 elif custom_main_mode == PX4_CUSTOM_MAIN_MODE_STABILIZED:
1978 elif custom_main_mode == PX4_CUSTOM_MAIN_MODE_ALTCTL:
1980 elif custom_main_mode == PX4_CUSTOM_MAIN_MODE_POSCTL:
1982 elif (base_mode & auto_mode_flags) == auto_mode_flags:
1983 if custom_main_mode & PX4_CUSTOM_MAIN_MODE_AUTO != 0:
1984 if custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_MISSION:
1986 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF:
1988 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LOITER:
1990 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET:
1992 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_RTL:
1994 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_LAND:
1996 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_AUTO_RTGS:
1998 elif custom_sub_mode == PX4_CUSTOM_SUB_MODE_OFFBOARD:
2003 '''return dictionary mapping mode names to numbers, or None if unknown''' 2005 if mav_type
in [mavlink.MAV_TYPE_QUADROTOR,
2006 mavlink.MAV_TYPE_HELICOPTER,
2007 mavlink.MAV_TYPE_HEXAROTOR,
2008 mavlink.MAV_TYPE_OCTOROTOR,
2009 mavlink.MAV_TYPE_COAXIAL,
2010 mavlink.MAV_TYPE_TRICOPTER]:
2011 map = mode_mapping_acm
2012 if mav_type == mavlink.MAV_TYPE_FIXED_WING:
2013 map = mode_mapping_apm
2014 if mav_type == mavlink.MAV_TYPE_GROUND_ROVER:
2015 map = mode_mapping_rover
2016 if mav_type == mavlink.MAV_TYPE_SURFACE_BOAT:
2017 map = mode_mapping_rover
2018 if mav_type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
2019 map = mode_mapping_tracker
2020 if mav_type == mavlink.MAV_TYPE_SUBMARINE:
2021 map = mode_mapping_sub
2024 inv_map = dict((a, b)
for (b, a)
in map.items())
2028 '''return dictionary mapping mode numbers to name, or None if unknown''' 2030 if mav_type
in [mavlink.MAV_TYPE_QUADROTOR,
2031 mavlink.MAV_TYPE_HELICOPTER,
2032 mavlink.MAV_TYPE_HEXAROTOR,
2033 mavlink.MAV_TYPE_OCTOROTOR,
2034 mavlink.MAV_TYPE_DODECAROTOR,
2035 mavlink.MAV_TYPE_COAXIAL,
2036 mavlink.MAV_TYPE_TRICOPTER]:
2037 map = mode_mapping_acm
2038 if mav_type == mavlink.MAV_TYPE_FIXED_WING:
2039 map = mode_mapping_apm
2040 if mav_type == mavlink.MAV_TYPE_GROUND_ROVER:
2041 map = mode_mapping_rover
2042 if mav_type == mavlink.MAV_TYPE_SURFACE_BOAT:
2043 map = mode_mapping_rover
2044 if mav_type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
2045 map = mode_mapping_tracker
2046 if mav_type == mavlink.MAV_TYPE_SUBMARINE:
2047 map = mode_mapping_sub
2054 '''mode string for 1.0 protocol, from heartbeat''' 2055 if msg.autopilot == mavlink.MAV_AUTOPILOT_PX4:
2057 if not msg.base_mode & mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED:
2058 return "Mode(0x%08x)" % msg.base_mode
2059 if msg.type
in [ mavlink.MAV_TYPE_QUADROTOR, mavlink.MAV_TYPE_HEXAROTOR,
2060 mavlink.MAV_TYPE_OCTOROTOR, mavlink.MAV_TYPE_TRICOPTER,
2061 mavlink.MAV_TYPE_COAXIAL,
2062 mavlink.MAV_TYPE_HELICOPTER ]:
2063 if msg.custom_mode
in mode_mapping_acm:
2064 return mode_mapping_acm[msg.custom_mode]
2065 if msg.type == mavlink.MAV_TYPE_FIXED_WING:
2066 if msg.custom_mode
in mode_mapping_apm:
2067 return mode_mapping_apm[msg.custom_mode]
2068 if msg.type == mavlink.MAV_TYPE_GROUND_ROVER:
2069 if msg.custom_mode
in mode_mapping_rover:
2070 return mode_mapping_rover[msg.custom_mode]
2071 if msg.type == mavlink.MAV_TYPE_SURFACE_BOAT:
2072 if msg.custom_mode
in mode_mapping_rover:
2073 return mode_mapping_rover[msg.custom_mode]
2074 if msg.type == mavlink.MAV_TYPE_ANTENNA_TRACKER:
2075 if msg.custom_mode
in mode_mapping_tracker:
2076 return mode_mapping_tracker[msg.custom_mode]
2077 if msg.type == mavlink.MAV_TYPE_SUBMARINE:
2078 if msg.custom_mode
in mode_mapping_sub:
2079 return mode_mapping_sub[msg.custom_mode]
2080 return "Mode(%u)" % msg.custom_mode
2083 '''return mode string for APM:Plane''' 2084 if mode_number
in mode_mapping_apm:
2085 return mode_mapping_apm[mode_number]
2086 return "Mode(%u)" % mode_number
2089 '''return mode string for APM:Copter''' 2090 if mode_number
in mode_mapping_acm:
2091 return mode_mapping_acm[mode_number]
2092 return "Mode(%u)" % mode_number
2095 '''x25 CRC - based on checksum.h from mavlink library''' 2101 '''add in some more bytes''' 2102 byte_buf = array.array(
'B')
2103 if isinstance(buf, array.array):
2104 byte_buf.extend(buf)
2106 byte_buf.fromstring(buf)
2109 tmp = b ^ (accum & 0xff)
2110 tmp = (tmp ^ (tmp<<4)) & 0xFF
2111 accum = (accum>>8) ^ (tmp<<8) ^ (tmp<<3) ^ (tmp>>4)
2112 accum = accum & 0xFFFF
2116 '''an object that looks like a serial port, but 2117 transmits using mavlink SERIAL_CONTROL packets''' 2118 def __init__(self, portname, baudrate, devnum=0, devbaud=0, timeout=3, debug=0):
2119 from .
import mavutil
2126 self.
debug(
"Connecting with MAVLink to %s ..." % portname)
2127 self.
mav = mavutil.mavlink_connection(portname, autoreconnect=
True, baud=baudrate)
2128 self.mav.wait_heartbeat()
2129 self.
debug(
"HEARTBEAT OK\n")
2132 self.
debug(
"Locked serial device\n")
2135 '''write some debug text''' 2140 '''write some bytes''' 2141 from .
import mavutil
2142 self.
debug(
"sending '%s' (0x%02x) of len %u\n" % (b, ord(b[0]), len(b)), 2)
2147 buf = [ord(x)
for x
in b[:n]]
2148 buf.extend([0]*(70-len(buf)))
2149 self.mav.mav.serial_control_send(self.
port,
2150 mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
2151 mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
2159 '''read some bytes into self.buf''' 2160 from .
import mavutil
2161 start_time = time.time()
2162 while time.time() < start_time + self.
timeout:
2163 m = self.mav.recv_match(condition=
'SERIAL_CONTROL.count!=0',
2164 type=
'SERIAL_CONTROL', blocking=
False, timeout=0)
2165 if m
is not None and m.count != 0:
2167 self.mav.mav.serial_control_send(self.
port,
2168 mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE |
2169 mavutil.mavlink.SERIAL_CONTROL_FLAG_RESPOND,
2173 m = self.mav.recv_match(condition=
'SERIAL_CONTROL.count!=0',
2174 type=
'SERIAL_CONTROL', blocking=
True, timeout=0.01)
2175 if m
is not None and m.count != 0:
2180 data = m.data[:m.count]
2181 self.
buf +=
''.join(
str(chr(x))
for x
in data)
2184 '''read some bytes''' 2185 if len(self.
buf) == 0:
2187 if len(self.
buf) > 0:
2188 if n > len(self.
buf):
2194 self.
debug(
"read 0x%x" % ord(b), 2)
2199 '''flush any pending input''' 2206 self.
debug(
"flushInput")
2210 from .
import mavutil
2214 self.mav.mav.serial_control_send(self.
port,
2215 mavutil.mavlink.SERIAL_CONTROL_FLAG_EXCLUSIVE,
2222 if __name__ ==
'__main__':
2223 serial_list =
auto_detect_serial(preferred_list=[
'*FTDI*',
"*Arduino_Mega_2560*",
"*3D_Robotics*",
"*USB_to_UART*",
'*PX4*',
'*FMU*'])
2224 for port
in serial_list:
def debug(self, s, level=1)
def auto_detect_serial_unix(preferred_list=['*'])
def __init__(self, filename, progress_callback=None)
def waypoint_count_send(self, seq)
def __init__(self, device, autoreconnect=False, source_system=255, source_component=0, retries=3, use_native=default_native)
def auto_detect_serial_win32(preferred_list=['*'])
def motors_armed_wait(self)
def param_fetch_one(self, name)
def waypoint_current(self)
def auto_mavlink_version(self, buf)
def setup_signing(self, secret_key, sign_outgoing=True, allow_unsigned_callback=None, initial_timestamp=None, link_id=None)
def __init__(self, lat, lng, alt=0, heading=0)
def set_baudrate(self, baudrate)
def post_message(self, msg)
def __init__(self, fd, address, source_system=255, source_component=0, notimestamps=False, input=True, use_native=default_native)
def accumulate(self, buf)
def param_fetch_all(self)
def set_rtscts(self, enable)
def do_connect(self, retries=3)
def time_since(self, mtype)
def mavgen_python_dialect(dialect, wire_protocol)
def flightmode_list(self)
def auto_detect_serial(preferred_list=['*'])
def mode_mapping_byname(mav_type)
def motors_disarmed_wait(self)
def location(self, relative_alt=False)
def setup_logfile_raw(self, logfile, mode='w')
def setup_logfile(self, logfile, mode='w')
def calibrate_pressure(self)
def __init__(self, device, input=True, broadcast=False, source_system=255, source_component=0, use_native=default_native)
def mode_mapping_bynumber(mav_type)
def set_mode_manual(self)
def check_condition(self, condition)
def waypoint_request_list_send(self)
def post_message(self, msg)
def probably_vehicle_heartbeat(self, msg)
def skip_to_type(self, type)
def interpret_px4_mode(base_mode, custom_mode)
def waypoint_clear_all_send(self)
def mavlink_connection(device, baud=115200, source_system=255, source_component=0, planner_format=None, write=False, append=False, robust_parsing=True, notimestamps=False, input=True, dialect=None, autoreconnect=False, zero_time_base=False, retries=3, use_native=default_native, force_connected=False, progress_callback=None)
def set_servo(self, channel, pwm)
def reboot_autopilot(self, hold_in_bootloader=False)
def mode_string_acm(mode_number)
def waypoint_set_current_send(self, seq)
def evaluate_expression(expression, vars)
def calibrate_level(self)
def __init__(self, portname, baudrate, devnum=0, devbaud=0, timeout=3, debug=0)
def disable_signing(self)
def waypoint_request_send(self, seq)
def __init__(self, filename, source_system=255, source_component=0, use_native=default_native)
def __init__(self, device, baud=115200, autoreconnect=False, source_system=255, source_component=0, use_native=default_native, force_connected=False)
def set_mode(self, mode, custom_mode=0, custom_sub_mode=0)
def __init__(self, filename, planner_format=None, write=False, append=False, robust_parsing=True, notimestamps=False, source_system=255, source_component=0, use_native=default_native)
def __init__(self, device, source_system=255, source_component=0, retries=3, use_native=default_native)
def select(self, timeout)
def recv_match(self, condition=None, type=None, blocking=False, timeout=None)
def field(self, type, field, default=None)
def set_mode_px4(self, mode, custom_mode, custom_sub_mode)
def __init__(self, buf='')
def init_arrays(self, progress_callback=None)
def recv_match(self, condition=None, type=None, blocking=False, timeout=None)
def set_relay(self, relay_pin=0, state=True)
resolved_destination_addr
def scan_timestamp(self, tbuf)
def mode_string_apm(mode_number)
def param_set_send(self, parm_name, parm_value, parm_type=None)
def set_mode_loiter(self)
def set_close_on_exec(fd)
def __init__(self, frequency)
def evaluate_condition(condition, vars)
def set_rtscts(self, enable)
def __init__(self, device, broadcast=False, source_system=255, source_component=0, use_native=default_native)
def set_mode_apm(self, mode, custom_mode=0, custom_sub_mode=0)
def param(self, name, default=None)
def setBaudrate(self, baudrate)
def __init__(self, device, description=None, hwid=None)
def wait_heartbeat(self, blocking=True, timeout=None)
def arducopter_disarm(self)
def set_mode_flag(self, flag, enable)
def mode_string_px4(MainState)