ardupilot-log-reader 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ from .reader import Ardupilot
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env python
2
+
3
+ '''
4
+ example program that dumps a Mavlink log file. The log file is
5
+ assumed to be in the format that qgroundcontrol uses, which consists
6
+ of a series of MAVLink packets, each with a 64 bit timestamp
7
+ header. The timestamp is in microseconds since 1970 (unix epoch)
8
+
9
+ This program is free software: you can redistribute it and/or modify it under
10
+ the terms of the GNU General Public License as published by the Free Software
11
+ Foundation, either version 3 of the License, or (at your option) any later
12
+ version.
13
+ This program is distributed in the hope that it will be useful, but WITHOUT
14
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
+ You should have received a copy of the GNU General Public License along with
17
+ this program. If not, see <http://www.gnu.org/licenses/>.
18
+ '''
19
+
20
+ from __future__ import print_function
21
+
22
+ import array
23
+ import fnmatch
24
+ import json
25
+ import os
26
+ import struct
27
+ import sys
28
+ import time
29
+
30
+ import pandas as pd
31
+
32
+ try:
33
+ from pymavlink.mavextra import *
34
+ except:
35
+ print("WARNING: Numpy missing, mathematical notation will not be supported..")
36
+
37
+ from argparse import ArgumentParser
38
+
39
+ import inspect
40
+
41
+ from pymavlink import mavutil
42
+
43
+
44
+ class Ardupilot(object):
45
+
46
+ def __init__(
47
+ self,
48
+ bin_file,
49
+ no_timestamps=False,
50
+ planner=False,
51
+ robust=False,
52
+ condition=None,
53
+ types=None,
54
+ nottypes=None,
55
+ dialect="ardupilotmega",
56
+ zero_time_base=False,
57
+ source_system=None,
58
+ source_component=None,
59
+ link=None,
60
+ mav10=False
61
+ ):
62
+ '''
63
+ parser.add_argument("--no-timestamps", dest="notimestamps", action='store_true', help="Log doesn't have timestamps")
64
+ parser.add_argument("--planner", action='store_true', help="use planner file format")
65
+ parser.add_argument("--robust", action='store_true', help="Enable robust parsing (skip over bad data)")
66
+ parser.add_argument("--condition", default=None, help="select packets by condition")
67
+ parser.add_argument("--types", default=None, help="types of messages (comma separated with wildcard)")
68
+ parser.add_argument("--nottypes", default=None, help="types of messages not to include (comma separated with wildcard)")
69
+ parser.add_argument("--dialect", default="ardupilotmega", help="MAVLink dialect")
70
+ parser.add_argument("--zero-time-base", action='store_true', help="use Z time base for DF logs")
71
+ parser.add_argument("--source-system", type=int, default=None, help="filter by source system ID")
72
+ parser.add_argument("--source-component", type=int, default=None, help="filter by source component ID")
73
+ parser.add_argument("--link", type=int, default=None, help="filter by comms link ID")
74
+ parser.add_argument("--mav10", action='store_true', help="parse as MAVLink1")
75
+ parser.add_argument("log", metavar="LOG")
76
+ '''
77
+
78
+ self._parms = None
79
+ if not mav10:
80
+ os.environ['MAVLINK20'] = '1'
81
+
82
+ filename = bin_file
83
+ mlog = mavutil.mavlink_connection(filename, planner_format=planner,
84
+ notimestamps=no_timestamps,
85
+ robust_parsing=robust,
86
+ dialect=dialect,
87
+ zero_time_base=zero_time_base)
88
+
89
+ ext = os.path.splitext(filename)[1]
90
+ isbin = ext in ['.bin', '.BIN', '.px4log']
91
+ islog = ext in ['.log', '.LOG'] # NOTE: "islog" does not mean a tlog
92
+ istlog = ext in ['.tlog', '.TLOG']
93
+
94
+ # Track types found
95
+ available_types = set()
96
+
97
+ types = list(set(types + ['PARM']))
98
+
99
+ if nottypes is not None:
100
+ nottypes = nottypes.split(',')
101
+
102
+ def match_type(mtype, patterns):
103
+ '''return True if mtype matches pattern'''
104
+ for p in patterns:
105
+ if fnmatch.fnmatch(mtype, p):
106
+ return True
107
+ return False
108
+
109
+ # for DF logs pre-calculate types list
110
+ match_types=None
111
+ if types is not None and hasattr(mlog, 'name_to_id'):
112
+ for k in mlog.name_to_id.keys():
113
+ if match_type(k, types):
114
+ if nottypes is not None and match_type(k, nottypes):
115
+ continue
116
+ if match_types is None:
117
+ match_types = []
118
+ match_types.append(k)
119
+
120
+ dfs_dicts = {}
121
+
122
+ self.read_types = types
123
+
124
+ while True:
125
+ m = mlog.recv_match(blocking=False, type=match_types)
126
+ if m is None:
127
+ break
128
+
129
+ if not mavutil.evaluate_condition(condition, mlog.messages):
130
+ continue
131
+ if source_system is not None and source_system != m.get_srcSystem():
132
+ continue
133
+ if source_component is not None and source_component != m.get_srcComponent():
134
+ continue
135
+ if link is not None and link != m._link:
136
+ continue
137
+
138
+ if types is not None and m.get_type() != 'BAD_DATA' and not match_type(m.get_type(), types):
139
+ continue
140
+
141
+ if nottypes is not None and match_type(m.get_type(), nottypes):
142
+ continue
143
+
144
+ # Ignore BAD_DATA messages is the user requested or if they're because of a bad prefix. The
145
+ # latter case is normally because of a mismatched MAVLink version.
146
+ if m.get_type() == 'BAD_DATA':
147
+ continue
148
+
149
+ # Grab the timestamp.
150
+ timestamp = getattr(m, '_timestamp', 0.0)
151
+
152
+ try:
153
+ dfs_dicts[m.get_type()]
154
+ except KeyError:
155
+ dfs_dicts[m.get_type()] = {}
156
+ dfs_dicts[m.get_type()]['timestamp'] = []
157
+ for field in m.get_fieldnames():
158
+ dfs_dicts[m.get_type()][field] = []
159
+
160
+ dfs_dicts[m.get_type()]['timestamp'].append( getattr(m,'_timestamp', 0.0) )
161
+ for field in m.get_fieldnames():
162
+ dfs_dicts[m.get_type()][field].append( getattr(m,field) )
163
+
164
+ self._dfs = {}
165
+ for msgType in dfs_dicts.keys():
166
+ self._dfs[msgType] = pd.DataFrame(data=dfs_dicts[msgType])
167
+
168
+ new_cols = []
169
+ for val in self._dfs[msgType].columns:
170
+ if val == 'timestamp':
171
+ new_cols.append(val)
172
+ else:
173
+ new_cols.append(msgType + val)
174
+
175
+ self._dfs[msgType].columns = new_cols
176
+
177
+ mlog.filehandle.close()
178
+
179
+ @property
180
+ def dfs(self):
181
+ return self._dfs
182
+
183
+ @property
184
+ def parms(self):
185
+ if not self._parms:
186
+ self._parms = self.dfs['PARM'].set_index('PARMName')['PARMValue'].to_dict()
187
+ return self._parms
188
+
189
+ def join_logs(self, titles):
190
+ """Merge logs on timestamp
191
+ """
192
+ available_titles = [title for title in titles if title in self.dfs.keys()]
193
+ joined_log = self.dfs[available_titles[0]]
194
+ for title in available_titles[1:]:
195
+ if title=='PARM':
196
+ continue
197
+ ln= len(self.dfs[title])
198
+ l0 = len(joined_log)
199
+ joined_log = pd.merge_asof(
200
+ joined_log,
201
+ self.dfs[title],
202
+ on='timestamp'
203
+ )
204
+ l1 = len(joined_log)
205
+ if l1 < l0:
206
+ pass
207
+ return joined_log
208
+
209
+ def full_df(self):
210
+ return self.join_logs(list(self.dfs.keys())) # TODO remove PARA from here.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: ardupilot-log-reader
3
+ Version: 0.1.0
4
+ Summary: module to read ardupilot binary logs to memory
5
+ Home-page: https://github.com/PyFlightCoach/ardupilot_log_reader
6
+ Author: Thomas David
7
+ Author-email: thomasdavid0@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: future
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas
12
+ Requires-Dist: pymavlink
13
+
14
+ # Ardupilot Log Reader
15
+
16
+ This package wraps untidily around mavlogdump in pymavlink, to read an ardupilot log to a pandas dataframe.
17
+
18
+ ## usage
19
+
20
+ #set up the parser
21
+ from ArdupilotLogReader import Ardupilot
22
+ parser = Ardupilot(
23
+ log_file, # the log file, .bin
24
+ types = ['ARSP', 'ATT', 'BARO', 'GPS', 'IMU', 'RCIN', 'RCOU', 'BAT', 'MODE', 'NKF1', 'STAT', 'XKF1'], # fields to read from the log
25
+ zero_time_base=True # arguments passed to pymavlink
26
+ )
27
+
28
+ parser.dfs # a dict containing a dataframes of log data for each field requested.
29
+ parser.join_logs(['ARSP', 'ATT']) #returns a pandas dataframe containing the ARSP and ATT data joined on time
30
+ parser.parms # returns the parameters read from the top of the log
31
+
@@ -0,0 +1,6 @@
1
+ ardupilot_log_reader/__init__.py,sha256=1TNBtnMDck14t_s5tg9ImmH_TiTRYKMUcoLWmU_HJ3k,29
2
+ ardupilot_log_reader/reader.py,sha256=o65KmmA1_DKNub316Exc4TPZeaMl1RFEezYT4qytoK0,7671
3
+ ardupilot_log_reader-0.1.0.dist-info/METADATA,sha256=cls7Kr8Y40s9f1ItCm43e0jjaTTxcxakQifCU6fT0ks,1092
4
+ ardupilot_log_reader-0.1.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ ardupilot_log_reader-0.1.0.dist-info/top_level.txt,sha256=HM02mAMFoVozMNx9PBicIppXB-jA3NFZdYCajocGBis,21
6
+ ardupilot_log_reader-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.38.4)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ ardupilot_log_reader