-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmultiprocessingTester.py
More file actions
77 lines (66 loc) · 3.18 KB
/
multiprocessingTester.py
File metadata and controls
77 lines (66 loc) · 3.18 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
import multiprocessing
import time
from arduinoComms import arduinoComms
from motorControl import motorControl
from ultrasonicReader import ultrasonicReader
from stateMachine import stateMachine
#import LoadShoot class
from LoadShoot import LoadShoot
def inputSimulator(motorController, ultrasonicDistance, exit_event):
# initialTime = time.time()
initialTime = 0
while not exit_event.is_set():
try:
if (time.time()-initialTime>1):
# motorController.writeTargetSteps([10, 10, 10, 10])
# chosenSpeed = input("enter desired turn distance: ")
# motorController.rotate(10)
# initialTime = time.time()
pass
readings = motorController.readCurrentSteps()
# print(f'current steps: {readings[0]}, {readings[1]}, {readings[2]}, {readings[3]} at {time.time()-initialTime}')
print(f'ultrasonic distance reading: {ultrasonicDistance.value}')
time.sleep(1)
except KeyboardInterrupt:
exit_event.set()
print("closing input simulator gracefully")
if __name__ == "__main__":
#declaring serial variables
# port = 'COM4' #For PC
port = '/dev/ttyACM0' #For Rpi
baud_rate = 115200
#declaring sensor variables
GPIO_TRIGGER = 18
GPIO_ECHO = 24
#declaring multiprocessing variables
exit_event = multiprocessing.Event()
sendTarget = multiprocessing.Value('i', False)
targetStep1 = multiprocessing.Value('i', 0)
targetStep2 = multiprocessing.Value('i', 0)
targetStep3 = multiprocessing.Value('i', 0)
targetStep4 = multiprocessing.Value('i', 0)
#shooting command variable. sent as 1 when shooting one puck.
#will shoot and load next puck, ensuring next puck ready to fire
ShootCommand = multiprocessing.Value('i', 0)
currentStep1 = multiprocessing.Value('i', 0)
currentStep2 = multiprocessing.Value('i', 0)
currentStep3 = multiprocessing.Value('i', 0)
currentStep4 = multiprocessing.Value('i', 0)
ultrasonicDistance = multiprocessing.Value('d', 9999)
#declare class objects
arduinoCommunication = arduinoComms(port, baud_rate, exit_event, sendTarget, targetStep1, targetStep2, targetStep3, targetStep4, ShootCommand, currentStep1, currentStep2, currentStep3, currentStep4)
motorController = motorControl(sendTarget, targetStep1, targetStep2, targetStep3, targetStep4, currentStep1, currentStep2, currentStep3, currentStep4)
#declare loading and shooting object
LoadShooter = LoadShoot(ShootCommand)
ultrasonicSensor = ultrasonicReader(exit_event, GPIO_TRIGGER, GPIO_ECHO, ultrasonicDistance)
decisionMaking = stateMachine(exit_event, motorController, ultrasonicDistance, LoadShooter)
process1 = multiprocessing.Process(target=arduinoCommunication.maintainCommunications)
process2 = multiprocessing.Process(target=ultrasonicSensor.iterateSensor)
process3 = multiprocessing.Process(target=decisionMaking.iteratestates)
# process3 = multiprocessing.Process(target=inputSimulator, args=[motorController, ultrasonicDistance, exit_event])
process1.start()
process2.start()
process3.start()
process1.join()
process2.join()
process3.join()