forked from T-Kuhn/StepperRobotArm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainLoop.py
92 lines (82 loc) · 3.1 KB
/
mainLoop.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
#!/usr/bin/python3
import time
import RPi.GPIO as GPIO
from stepperRobotArm import StepperRobotArm
from replicaRobotArm import ReplicaRobotArm
from blinkLED import BlinkLED
from button import Button
from switch import Switch
import pigpio
# - - - - - - - - - - - - - - - -
# - - - - - GPIO Setup - - - - -
# - - - - - - - - - - - - - - - -
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN) # Save button
GPIO.setup(16,GPIO.IN) # Reset button
GPIO.setup(6, GPIO.IN) # Not Used
GPIO.setup(13, GPIO.IN) # Endless Repeat switch
GPIO.setup(19, GPIO.IN) # Set Origin switch
GPIO.setup(26, GPIO.IN) # Follow switch
GPIO.setup(12, GPIO.IN) # Repeat switch
GPIO.setup(21, GPIO.OUT) # Blink LED
servoGripperPin = 24 # Servo Gripper
# - - - - - - - - - - - - - - - -
# - - - Global Objects - - - - -
# - - - - - - - - - - - - - - - -
pi = pigpio.pi('localhost', 8888)
blinkLED = BlinkLED(21)
stepperArm = StepperRobotArm(blinkLED, pi, servoGripperPin)
replicaArm = ReplicaRobotArm()
replayButton = Button(20, stepperArm.shortPressAction, lambda: True)
deleteButton = Button(16, stepperArm.deleteReplayList, lambda: True)
notUsedSwitch = Switch(6, lambda: True, lambda: True)
endlessRepeatSwitch = Switch(13, lambda: stepperArm.setEndlessReplay(True), lambda: stepperArm.setEndlessReplay(False))
setOriginSwitch = Switch(19, replicaArm.getCorrValues, lambda: True)
followSwitch = Switch(26, lambda: stepperArm.setMode('follow'), lambda: stepperArm.setMode('idle'))
repeatSwitch = Switch(12, lambda: stepperArm.setMode('replay'), lambda: stepperArm.setMode('idle'))
# - - - - - - - - - - - - - - - -
# - - - UPDATE INPUT DEVICES - -
# - - - - - - - - - - - - - - - -
def updateInputDevices():
replayButton.update()
deleteButton.update()
notUsedSwitch.update()
endlessRepeatSwitch.update()
setOriginSwitch.update()
followSwitch.update()
repeatSwitch.update()
# - - - - - - - - - - - - - - - -
# - - UPDATE OUTPUT DEVICES - -
# - - - - - - - - - - - - - - - -
def updateOutputDevices():
blinkLED.update()
# - - - - - - - - - - - - - - - -
# - - - - UPDATE ROBOT ARM - - -
# - - - - - - - - - - - - - - - -
def updateRobotArm():
if stepperArm.mode is 'follow':
if stepperArm.checkIfIdle():
stepperArm.moveToPosition(replicaArm.posDict)
stepperArm.moveGripperToPosition(replicaArm.servoPos)
elif stepperArm.mode is 'replay':
if stepperArm.checkIfIdle():
if stepperArm.replayStepList:
blinkLED.setMode('slowBlink')
reciever, command = stepperArm.replayStepList.pop(0)
print(reciever, command)
if reciever is 'arm':
stepperArm.moveToPositionRaw(command)
if reciever is 'gripper':
stepperArm.moveGripperToPosition(command)
else:
blinkLED.setMode('idle')
stepperArm.replayEnded()
# - - - - - - - - - - - - - - - -
# - - - - - MAIN LOOP - - - - - -
# - - - - - - - - - - - - - - - -
while True:
updateInputDevices()
updateOutputDevices()
replicaArm.update()
updateRobotArm()
time.sleep(0.15)