-
Notifications
You must be signed in to change notification settings - Fork 1
/
Leap_init.py
122 lines (92 loc) · 3.13 KB
/
Leap_init.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
import os, sys, inspect, thread, time, serial
import Leap
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
ser=serial.Serial('/dev/tty.usbmodem1422',115200)
print ser.name + "Connected To FRDM K64"
Command =str(input("Motor Command"))
if (Command =="x"):
ser.write('x')
elif (Command =="s"):
for i in range (0,10000):
ser.write('s')
print "."
def main():
class SampleListener(Leap.Listener):
# when sensor connected - invoke when sensor connected
def on_connect(self, controller):
print "Connected"
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE)
def on_frame(self, controller):
#count = count + 1
frame = controller.frame()
hand = frame.hands.rightmost
rotation_y = hand.palm_position
for hand in frame.hands:
handType = "left hand" if hand.is_left else "right hand"
print handType + "palm position : "
Throttle = hand.palm_position[1]
print Throttle
print " "
normal = hand.palm_normal
direction = hand.direction
pitch = direction.pitch*Leap.RAD_TO_DEG
roll = normal.roll*Leap.RAD_TO_DEG
yaw = direction.yaw*Leap.RAD_TO_DEG
print "Pitch : " + str(pitch) + " Roll : "+str(roll)+ " Yaw : "+str(yaw)
if (Throttle>250):
print "Throttle"
ser.write('S')
elif (Throttle<100):
print "Stop"
ser.write('X')
elif (pitch < -15 and roll> 15):
print "forward Left"
ser.write('Q')
elif (pitch < -15 and roll <-15):
print "forward Right"
ser.write('E')
elif (pitch >15 and roll <-15):
print " backward Right"
ser.write('C')
elif (pitch >15 and roll > 15):
print "backward left"
ser.write('Z')
elif pitch < -15:
print "Forward"
ser.write('F')
elif pitch >15:
print "Backward"
ser.write('B')
elif roll <-15:
print "Right"
ser.write('R')
elif roll > 15:
print "Left"
ser.write('L')
elif yaw >15:
print "Rudder Right"
ser.write('>')
elif yaw <-15:
print "Rudder Left"
ser.write('<')
elif (pitch > -15 and pitch<15 and roll >-15 and roll < 15):
print "hover"
ser.write('H')
# print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % (frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures()))
# print "grab strength hand x: %d, palm position: %d, hands: %d,rotation: %d, tools: %d, gestures: %d" % (hand.grab_strength, hand.palm_position, len(frame.hands), rotation_y, len(frame.tools), len(frame.gestures()))
listener = SampleListener()
controller = Leap.Controller()
# Have the sample listener receive events from the controller
controller.add_listener(listener)
# Keep this process running until Enter is pressed
# Keep this process running until Enter is pressed
print "Press Enter to quit..."
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
# Remove the sample listener when done
controller.remove_listener(listener)
if __name__ == "__main__":
main()