-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMSPplotting.py
48 lines (36 loc) · 957 Bytes
/
MSPplotting.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
38
39
40
41
42
43
44
45
46
47
48
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import threading
import numpy as np
from MultiWiiProtocol import MSPio
signal = {'x': [], 'y': [], 'z': []}
fig, ax = plt.subplots()
lines = [ax.plot([], [])[0] for _ in signal.keys()]
timelim = ()
def stream():
att = ser.read_attitude()
signal['x'].append(att['x'])
signal['y'].append(att['y'])
signal['z'].append(att['heading'])
if ser.is_open():
threading.Timer(10/1000., stream).start()
def update(i):
global timelim
ax.relim()
ax.autoscale_view()
if ax.get_ylim() != timelim:
timelim = ax.get_ylim()
fig.canvas.draw()
for k, line in zip(signal.keys(), lines):
_, ly = line.get_data()
ly = np.append(ly, signal[k])
_xdata = np.arange(ly.size)
line.set_data(_xdata, ly)
signal[k] = []
return lines,
if __name__ == '__main__':
ser = MSPio()
if ser.is_open():
ani = animation.FuncAnimation(fig, update, interval=20)
stream()
plt.show()