forked from MumbleJumble21/Software-Senior-Design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.py
More file actions
125 lines (116 loc) · 5.77 KB
/
Copy pathController.py
File metadata and controls
125 lines (116 loc) · 5.77 KB
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
# Package imports.
from evdev import InputDevice, categorize, ecodes # Measures specified Linux input devices being broadcasted in '/dev/input'. Used to interface Bluetooth controller.
from PCA9685 import PCA9685 # Proprietary library needed to get specific servo HAT used in this year's project.
# Initialize PCA9685 library as object.
pwm = PCA9685()
# Set PWMFreq that servos will respond to (requires math, your value will most likely be different. See your servo product specs for provided PWM formula!)
pwm.setPWMFreq(50)
# For this specific HAT, all pulses had to be "initalized" with a zero value before they could be used.
pwm.setServoPulse(0,0)
pwm.setServoPulse(4,0)
pwm.setServoPulse(8,0)
pwm.setServoPulse(12,0)
# Specify input device we will be listening to by pointing to event "file".
device = InputDevice('/dev/input/event6')
print("Beep boop! You are using device:", device)
# Calculated PWM pulse values that make the robot move in set direction.
full_backward = 10
half_backward = 50
per_backward = 65
full_forward = 150
half_forward = 100
per_forward = 125
# PWM will only pulse once, to keep the signal constant we need to put in a loop. Event "codes" can be found in documentation of evdev library.
while True:
for event in device.read_loop():
if(event.code == 17):
if(event.value == -1):
'''Forward movement, 0 and 4 get 150 for normal forward
and 8 and 12 get 10 for backward movement since they have
a gear atached to them
'''
pwm.setRotationAngle(0,per_forward)
pwm.setRotationAngle(8,per_backward)
if(event.value == 0):
'''No movement'''
pwm.setRotationAngle(0,0)
pwm.setRotationAngle(8,0)
if(event.value == 1):
'''Forward movement, 0 and 4 get 10 for normal backward
and 8 and 12 get 10 for forward movement since they have
a gear atached to them
'''
pwm.setRotationAngle(0,per_backward)
pwm.setRotationAngle(8,per_forward)
if(event.code == 16):
if(event.value == -1):
'''Turning Left'''
pwm.setRotationAngle(0,full_backward)
pwm.setRotationAngle(8,full_backward)
if(event.value == 0):
'''No movement'''
pwm.setRotationAngle(0,0)
pwm.setRotationAngle(4,0)
pwm.setRotationAngle(8,0)
pwm.setRotationAngle(12,0)
if(event.value == 1):
'''Turning right'''
pwm.setRotationAngle(0,full_forward)
pwm.setRotationAngle(8,full_forward)
if(event.type == ecodes.EV_MSC):
'''Detect A, B, X, Y buttons'''
if(event.code == 4):
if(event.value == 589825):
'''A key moves conveyor belt backwards'''
pwm.setRotationAngle(4,full_backward)
if(event.value == 589826):
'''B key rotates moves delivery tray down'''
pwm.setRotationAngle(12,full_backward)
if(event.value == 589828):
'''X key rotates conveyor belt forwards'''
pwm.setRotationAngle(4,full_forward)
if(event.value == 589829):
'''Y key moves delivery tray up'''
pwm.setRotationAngle(12,full_forward)
if(event.type == ecodes.EV_KEY):
if(event.code == 304):
if(event.value == 0):
'''Stopping A key press'''
pwm.setRotationAngle(4,0)
if(event.code == 305):
if(event.value == 0):
'''Stopping B key press'''
pwm.setRotationAngle(12,0)
if(event.code == 307):
if(event.value == 0):
'''Stopping X key press'''
pwm.setRotationAngle(4,0)
if(event.code == 308):
if(event.value == 0):
'''Stopping Y key press'''
pwm.setRotationAngle(12,0)
if(event.type == ecodes.EV_ABS):
if(event.code == 10):
if(event.value == 1023):
print("Left trigger down")
pwm.setRotationAngle(3,50)
pwm.setRotationAngle(7,50)
pwm.setRotationAngle(11,50)
pwm.setRotationAngle(15,50)
if(event.value == 0):
pwm.setRotationAngle(3,0)
pwm.setRotationAngle(7,0)
pwm.setRotationAngle(11,0)
pwm.setRotationAngle(15,0)
if(event.code == 9):
if(event.value == 1023):
print("Right trigger down")
pwm.setRotationAngle(3,100)
pwm.setRotationAngle(7,100)
pwm.setRotationAngle(11,100)
pwm.setRotationAngle(15,100)
if(event.value ==0):
pwm.setRotationAngle(3,0)
pwm.setRotationAngle(7,0)
pwm.setRotationAngle(11,0)
pwm.setRotationAngle(15,0)