4 fit best estimate of magnetometer offsets 6 from __future__
import print_function
11 from argparse
import ArgumentParser
12 parser = ArgumentParser(description=__doc__)
13 parser.add_argument(
"--condition", default=
None, help=
"select packets by condition")
14 parser.add_argument(
"--sample-length", type=int, default=0, help=
"number of samples to run FFT over")
15 parser.add_argument(
"logs", metavar=
"LOG", nargs=
"+")
17 args = parser.parse_args()
19 from pymavlink
import mavutil
22 '''display fft for raw ACC data in logfile''' 24 print(
"Processing log %s" % filename)
25 mlog = mavutil.mavlink_connection(filename)
27 data = {
'ACC1.rate' : 1000,
33 for acc
in [
'ACC1',
'ACC2',
'ACC3']:
34 for ax
in [
'AccX',
'AccY',
'AccZ']:
36 for gyr
in [
'GYR1',
'GYR2',
'GYR3']:
37 for ax
in [
'GyrX',
'GyrY',
'GyrZ']:
42 m = mlog.recv_match(condition=args.condition)
46 if type.startswith(
"ACC"):
47 data[type+
'.AccX'].append(m.AccX)
48 data[type+
'.AccY'].append(m.AccY)
49 data[type+
'.AccZ'].append(m.AccZ)
50 if type.startswith(
"GYR"):
51 data[type+
'.GyrX'].append(m.GyrX)
52 data[type+
'.GyrY'].append(m.GyrY)
53 data[type+
'.GyrZ'].append(m.GyrZ)
55 print(
"Extracted %u data points" % len(data[
'ACC1.AccX']))
57 for msg
in [
'ACC1',
'ACC2',
'ACC3',
'GYR1',
'GYR2',
'GYR3']:
60 if msg.startswith(
'ACC'):
64 for axis
in [
'X',
'Y',
'Z']:
65 field = msg +
'.' + prefix + axis
67 if args.sample_length != 0:
68 d = d[0:args.sample_length]
72 avg = numpy.sum(d) / len(d)
74 d_fft = numpy.fft.rfft(d)
75 freq = numpy.fft.rfftfreq(len(d), 1.0 / data[msg+
'.rate'])
76 pylab.plot( freq, numpy.abs(d_fft), label=field )
77 pylab.legend(loc=
'upper right')
79 for filename
in args.logs: