-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmain.py
More file actions
106 lines (76 loc) · 3.77 KB
/
main.py
File metadata and controls
106 lines (76 loc) · 3.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
# This is the main file for the ArmTeam project. It initializes and runs the arm control system.
# It sets up the arm hardware interface, the controler, the server, and the app. It also handles command line arguments and configuration settings.
import subprocess
import sys
import os
# Add the project root to the Python path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from Config.ArmRuntime import ArmRuntime
from Config.ArmConfig import ArmConfig
if __name__ == "__main__":
# ----------------- SETUP -----------------
print("Arm startup")
keep_running = True
armConfig = ArmConfig() # class that will load the config file and parse the args
armRuntime = ArmRuntime() # class that will hold all the modules and handle the commands
config = armConfig.load_config('config.json') # load the config file
armConfig.parse_args(config) # parse the command line args and update the config file if needed
armRuntime.apply_config(config) # apply the config to the armRuntime class
print(armRuntime.modules_to_string()) # print loaded modules to the console
# Start arm, could mean connecting to the simulator or the real arm
armRuntime.selected_HAL.start_arm()
print("Controler Startup")
# Start the Controler
if armRuntime.selected_controller is not None:
armRuntime.selected_controller.start()
armRuntime.start(config) # start the rest of the modules
# start listening to speech
if armRuntime.selected_stt is not None and not config["stt_push_to_talk"]:
armRuntime.selected_stt.activate()
if armRuntime.selected_tts is not None:
armRuntime.selected_tts.say("Arm startup.")
# ----------------- END SETUP -----------------
# ----------------- MAIN PROGRAM LOOP -----------------
# will capture main thread and run the input loop in a separate thread
if config["use_server"]:
print("Server Startup")
armRuntime.selected_server.start_server()
# will capture main thread and run the input loop in a separate thread
if config["use_app"]:
try:
armRuntime.console_input.run_input_looping_async()
armRuntime.selected_app.start_app()
except KeyboardInterrupt:
keep_running = False
# if we are not using the server or the app, we will run the input loop in the main thread
if not config["use_app"]:
while keep_running:
print("Arm is running, press 'q' or ctrl-c to quit")
try:
armRuntime.console_input.run_input_looping()
except KeyboardInterrupt:
keep_running = False
# ----------------- END MAIN PROGRAM LOOP -----------------
# ----------------- CLEAUP / SHUTDOWN -----------------
print("Arm shutdown")
keep_running = False
# stop listening to speech
if armRuntime.selected_stt is not None:
armRuntime.selected_stt.stop()
# stop the server
if armRuntime.selected_server is not None:
armRuntime.selected_server.stop_server()
# stop the controller
if armRuntime.selected_controller is not None:
armRuntime.selected_controller.stop()
# stop the HAL interface, could mean disconnecting from the simulator or the real arm
armRuntime.selected_HAL.stop_arm()
armRuntime.stop(config) # stop the rest of the modules
# speak a shutdown message
if armRuntime.selected_tts is not None:
armRuntime.selected_tts.say("Arm shutdown.")
print("Arm shutdown complete")
# Reopen Startup page
if config["open_startup_page"]:
subprocess.Popen(['python', 'ArmTeam/startup.py'])
# ----------------- END CLEAUP / SHUTDOWN -----------------