-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_gesture.py
139 lines (83 loc) · 2.61 KB
/
py_gesture.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
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
130
131
132
133
134
135
136
137
138
139
import serial
import time
import pyautogui
# Plot-real-time :
#import psutil
import matplotlib.pyplot as plt
from itertools import count
from matplotlib.animation import FuncAnimation # -- important for real time plots --
# For plot:
plt.style.use('seaborn')
fig, (ax1, ax2) = plt.subplots(2)
fig.suptitle('Plot on Distance v/s Time measured by sensors')
j=0
t1_value, t2_value, y_value, z_value = [], [], [], []
index1 = count()
index2 = count()
#Create Serial Port :
ArdunioSerial = serial.Serial('com10', 9600)
def animate(i):
incoming = str(ArdunioSerial.readline())
incoming = incoming.lstrip("b")
incoming = incoming.strip("'")
incoming = incoming.rstrip("\\r\\n")
print(incoming)
# Left sensor data :
incoming1 = incoming
left_sensor_reading = 0
if incoming1[0] == 'L':
incoming_left = incoming1.lstrip("L:")
t1_value.append(next(index1))
y_value.append(incoming_left)
xlim1 = int(next(index1))
ax1.plot(t1_value, y_value, color='b')
ax1.legend(['Left sensor'], loc='upper left')
ax1.set_xlabel('Time (in sec)')
ax1.set_ylabel('Left sensor(in cm)')
ax1.set_xlim(left=max(1,xlim1-60), right=xlim1+60)
# Right Sensor data :
incoming2 = incoming
if incoming2[0] == 'R':
incoming_right = incoming2.lstrip("R:")
t2_value.append(next(index2))
z_value.append(incoming_right)
plt.cla() # -- makes color constant --
xlim2 = int(next(index2))
ax2.plot(t2_value, z_value, color='orange')
ax2.legend(['Right sensor'], loc='upper left')
ax2.set_xlabel('Time (in sec)')
ax2.set_ylabel('right sensor(in cm)')
ax2.set_xlim(left=max(1,xlim2-60), right=xlim2+60)
# Control Keyboard Keys :
# both Sensor :
if "Play/Pause" in incoming:
pyautogui.typewrite(['space'], 0.2)
# LEFT Sensor :
if 'Escape' in incoming:
pyautogui.press('backspace')
pyautogui.keyUp('win')
if 'CTabs' in incoming:
pyautogui.keyDown('win')
if 'Vdow' in incoming :
pyautogui.hotkey('ctrl','down')
pyautogui.keyUp('win')
if 'Vup' in incoming :
pyautogui.hotkey('ctrl','up')
pyautogui.keyUp('win')
# RIGHT Sensor :
if 'Ente' in incoming:
pyautogui.press('enter')
pyautogui.keyUp('win')
if 'Tab' in incoming:
pyautogui.press('tab')
pyautogui.keyUp('win')
if 'FForward' in incoming:
pyautogui.hotkey('ctrl','right')
pyautogui.keyUp('win')
if 'FRewind' in incoming:
pyautogui.hotkey('ctrl','left')
pyautogui.keyUp('win')
ani = FuncAnimation(fig, animate, interval=100)
plt.tight_layout()
plt.show()
print('-------------')