This repository was archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_pose_listener.py
85 lines (65 loc) · 1.73 KB
/
print_pose_listener.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
import sys
sys.path.append('../lib/')
from device_listener import DeviceListener
from pose_type import PoseType
# Servo Control
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
# set to be a PWM output
servoPin1 = 12
servoPin2 = 13
servoPin3 = 15
servoPin4 = 16
servoPin5 = 18
GPIO.setup(servoPin1, GPIO.OUT)
GPIO.setup(servoPin2, GPIO.OUT)
GPIO.setup(servoPin3, GPIO.OUT)
GPIO.setup(servoPin4, GPIO.OUT)
GPIO.setup(servoPin5, GPIO.OUT)
p1 = GPIO.PWM(servoPin1, 50)
p2 = GPIO.PWM(servoPin2, 50)
p3 = GPIO.PWM(servoPin3, 50)
p4 = GPIO.PWM(servoPin4, 50)
p5 = GPIO.PWM(servoPin5, 50)
p1.start(7)
p2.start(7)
p3.start(7)
p4.start(7)
p5.start(7)
class PrintPoseListener(DeviceListener):
def on_pose(self, pose):
pose_type = PoseType(pose)
print(pose_type.name)
rotate(pose_type.name)
def rotate(name):
if name == "FIST":
p1.ChangeDutyCycle(11)
p2.ChangeDutyCycle(11)
p3.ChangeDutyCycle(11)
p4.ChangeDutyCycle(11)
p5.ChangeDutyCycle(11)
elif name == "WAVE_OUT":
p1.ChangeDutyCycle(11)
p2.ChangeDutyCycle(2)
p3.ChangeDutyCycle(2)
p4.ChangeDutyCycle(2)
p5.ChangeDutyCycle(11)
elif name == "WAVE_IN":
p1.ChangeDutyCycle(2)
p2.ChangeDutyCycle(11)
p3.ChangeDutyCycle(11)
p4.ChangeDutyCycle(2)
p5.ChangeDutyCycle(2)
elif name == "REST":
p1.ChangeDutyCycle(2)
p2.ChangeDutyCycle(2)
p3.ChangeDutyCycle(2)
p4.ChangeDutyCycle(2)
p5.ChangeDutyCycle(2)
elif name == "FINGERS_SPREAD":
p1.ChangeDutyCycle(2)
p2.ChangeDutyCycle(11)
p3.ChangeDutyCycle(11)
p4.ChangeDutyCycle(11)
p5.ChangeDutyCycle(11)
# time.sleep(delay_period)