-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathexample.py
More file actions
129 lines (109 loc) · 3.9 KB
/
example.py
File metadata and controls
129 lines (109 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
"""
example on how to plot decoded sensor data from crazyflie
@author: jsschell
"""
import cfusdlog
import matplotlib.pyplot as plt
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("filename")
args = parser.parse_args()
# decode binary log data
logData = cfusdlog.decode(args.filename)
#only focus on regular logging
logData = logData['fixedFrequency']
# set window background to white
plt.rcParams['figure.facecolor'] = 'w'
# number of columns and rows for suplot
plotCols = 1
plotRows = 1
# let's see which keys exists in current data set
keys = ""
for k, v in logData.items():
keys += k
# get plot config from user
plotGyro = 0
if re.search('gyro', keys):
inStr = input("plot gyro data? ([Y]es / [n]o): ")
if ((re.search('^[Yy]', inStr)) or (inStr == '')):
plotGyro = 1
plotRows += 1
plotAccel = 0
if re.search('acc', keys):
inStr = input("plot accel data? ([Y]es / [n]o): ")
if ((re.search('^[Yy]', inStr)) or (inStr == '')):
plotAccel = 1
plotRows += 1
plotBaro = 0
if re.search('baro', keys):
inStr = input("plot barometer data? ([Y]es / [n]o): ")
if ((re.search('^[Yy]', inStr)) or (inStr == '')):
plotBaro = 1
plotRows += 1
plotCtrl = 0
if re.search('ctrltarget', keys):
inStr = input("plot control data? ([Y]es / [n]o): ")
if ((re.search('^[Yy]', inStr)) or (inStr == '')):
plotCtrl = 1
plotRows += 1
plotStab = 0
if re.search('stabilizer', keys):
inStr = input("plot stabilizer data? ([Y]es / [n]o): ")
if ((re.search('^[Yy]', inStr)) or (inStr == '')):
plotStab = 1
plotRows += 1
# current plot for simple subplot usage
plotCurrent = 0
# new figure
plt.figure(0)
if plotGyro:
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['gyro.x'], '-', label='X')
plt.plot(logData['timestamp'], logData['gyro.y'], '-', label='Y')
plt.plot(logData['timestamp'], logData['gyro.z'], '-', label='Z')
plt.xlabel('timestamp [ms]')
plt.ylabel('Gyroscope [°/s]')
plt.legend(loc=9, ncol=3, borderaxespad=0.)
if plotAccel:
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['acc.x'], '-', label='X')
plt.plot(logData['timestamp'], logData['acc.y'], '-', label='Y')
plt.plot(logData['timestamp'], logData['acc.z'], '-', label='Z')
plt.xlabel('timestamp [ms]')
plt.ylabel('Accelerometer [g]')
plt.legend(loc=9, ncol=3, borderaxespad=0.)
if plotBaro:
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['baro.pressure'], '-')
plt.xlabel('timestamp [ms]')
plt.ylabel('Pressure [hPa]')
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['baro.temp'], '-')
plt.xlabel('timestamp [ms]')
plt.ylabel('Temperature [degC]')
if plotCtrl:
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['ctrltarget.roll'], '-', label='roll')
plt.plot(logData['timestamp'], logData['ctrltarget.pitch'], '-', label='pitch')
plt.plot(logData['timestamp'], logData['ctrltarget.yaw'], '-', label='yaw')
plt.xlabel('timestamp [ms]')
plt.ylabel('Control')
plt.legend(loc=9, ncol=3, borderaxespad=0.)
if plotStab:
plotCurrent += 1
plt.subplot(plotRows, plotCols, plotCurrent)
plt.plot(logData['timestamp'], logData['stabilizer.roll'], '-', label='roll')
plt.plot(logData['timestamp'], logData['stabilizer.pitch'], '-', label='pitch')
plt.plot(logData['timestamp'], logData['stabilizer.yaw'], '-', label='yaw')
plt.plot(logData['timestamp'], logData['stabilizer.thrust'], '-', label='thrust')
plt.xlabel('timestamp [ms]')
plt.ylabel('Stabilizer')
plt.legend(loc=9, ncol=4, borderaxespad=0.)
plt.show()