-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXYZController.py
78 lines (72 loc) · 1.9 KB
/
XYZController.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
import RPi.GPIO as GPIO
import time
gpios = {
"X":{
"gpio":21,
"currentPosition":0,
"stepSize":5,
"state": "stopped",
"total_degrees": 180,
"maxDC":13,
"minDC":1,
"instance":"",
"pause":1
},
"Y":{
"gpio":13,
"currentPosition":0,
"stepSize":5,
"state": "stopped",
"total_degrees": 180,
"maxDC":13,
"minDC":1,
"instance":"",
"pause":1
},
"Z":{
"gpio":26,
"currentPosition":0,
"stepSize":30,
"state": "stopped",
"total_degrees": 180,
"maxDC":13,
"minDC":1,
"instance":"",
"pause":1
}
}
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
def initializeServos():
for key, values in gpios.items():
try:
GPIO_PIN = values["gpio"]
print("[INFO] Setting up GPIO PIN "+ str(GPIO_PIN))
GPIO.setup(GPIO_PIN, GPIO.OUT)
temp = GPIO.PWM(GPIO_PIN,50)
temp.start(1)
gpios[key]["instance"] = temp
gpios[key]["state"] = "running"
except expression as identifier:
print(iden)
pass
def moveServos(axis, direction):
gpio = gpios[axis]
gpioInstance = gpio["instance"]
nextPosition = gpio["currentPosition"]
stepSize = gpio["stepSize"]
totalDegrees = gpio["total_degrees"]
maxDC = gpio["maxDC"]
minDC = gpio["minDC"]
if direction == "plus":
nextPosition += stepSize
else :
nextPosition -= stepSize
if nextPosition > 180 or nextPosition < 0 : return False
print("[INFO] Moving to degree "+ str(nextPosition))
dc = (nextPosition/totalDegrees) * maxDC
if dc < 1: dc = minDC
gpios[axis]["currentPosition"] = nextPosition
print("[INFO] Passing DC Value "+ str(dc))
gpioInstance.ChangeDutyCycle(dc)
pass