-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm_test.py
85 lines (57 loc) · 1.98 KB
/
arm_test.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
import time
import threading
from threading import Event
from control import (
handle_operating_mode,
OperatingMode,
Arm ,
XboxController,
SoundEffects,
handle_check_mode,
play_check_mode_sound,
)
def main():
arm = Arm()
joy = XboxController()
sounds_effects = SoundEffects()
operating_mode = OperatingMode.EMERGENCY_STOP
end_event = Event()
reset_event = Event()
end_event.set()
reset_event.clear()
background_thread = threading.Thread(
target=background_control, args=(arm, end_event, reset_event)
)
background_thread.start()
while True:
control_inputs = joy.read()
new_operating_mode = handle_operating_mode(control_inputs["operating_mode"])
#Change Operating Mode
if new_operating_mode and operating_mode != new_operating_mode:
operating_mode = new_operating_mode
sounds_effects.play_change_mode()
# Notify currently active mode
if handle_check_mode(control_inputs["check_mode"]):
play_check_mode_sound(operating_mode, sounds_effects)
# Pause the stationary background threads if the operating mode is not stationary
if operating_mode != OperatingMode.STATIONARY:
end_event.set()
reset_event.clear()
# Sending Commands to arm
if operating_mode == OperatingMode.ROBOTIC_ARM:
arm.handle_input(*control_inputs["arm"])
elif operating_mode == OperatingMode.STATIONARY:
# Reset the flags for the stationary mode threads
if end_event.is_set():
end_event.clear()
reset_event.set()
time.sleep(0.01)
def background_control(arm: Arm, end_event: Event, reset_event: Event):
while True:
if end_event.is_set():
arm.move_to_home()
reset_event.wait()
arm.move_random(t=4000)
time.sleep(3)
if __name__ == "__main__":
main()