-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
37 lines (31 loc) · 974 Bytes
/
plot.py
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
import argparse
import matplotlib.pyplot as plt
from pymavlink import mavutil
import mavlink_all as mavlink
parser = argparse.ArgumentParser()
parser.add_argument('input')
parser.add_argument('plot')
args = parser.parse_args()
args_input: str = args.input
args_plot: str = args.plot
data_x, data_y = tuple(args_plot.split(','))
msg_x, field_x = tuple(data_x.split('.'))
msg_y, field_y = tuple(data_y.split('.'))
x = []
y = []
mav = mavlink.MAVLink(None)
with open(args_input, 'rb') as file:
while (byte := file.read(1)):
try:
message = mav.parse_char(byte)
if message is not None:
# print(message)
message: mavlink.MAVLink_message
if message.get_type() == msg_x:
x.append(message.to_dict()[field_x])
if message.get_type() == msg_y:
y.append(message.to_dict()[field_y])
except:
pass
plt.plot(x, y)
plt.show()