-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
executable file
·173 lines (155 loc) · 4.46 KB
/
quickstart.py
File metadata and controls
executable file
·173 lines (155 loc) · 4.46 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
from optparse import OptionParser
from subprocess import check_output, Popen
import time
import sys
from enum import Enum
class Action(Enum):
KEYBOARD_CONTROL = 0
RUN_TESTS = 1
WEB_SERVER = 2
API_SERVER = 3
I2C_CHECK = 4
ULTRASONICS_READ = 5
STYLE_CHECKER = 6
EMERGENCY_STOP = 7
KEYBOARD_CONTROL_COLLISION = 8
FULL_CONTROL = 9
parser = OptionParser()
parser.add_option(
"-k",
"--keyboard-control",
action="store_const",
const=Action.KEYBOARD_CONTROL,
dest="action",
help="Start the keyboard control test script.")
parser.add_option(
"-f",
"--full-control",
action="store_const",
const=Action.FULL_CONTROL,
dest="action",
help="Start the keyboard control test script and arm control.")
parser.add_option(
"-c",
"--keyboard-control-collision",
action="store_const",
const=Action.KEYBOARD_CONTROL_COLLISION,
dest="action",
help="Start the keyboard control test script with ultrasonic sensors.")
parser.add_option(
"-t",
"--run-tests",
action="store_const",
const=Action.RUN_TESTS,
dest="action",
help="Run the unit test suite.")
parser.add_option(
"-w",
"--web-server",
action="store_const",
const=Action.WEB_SERVER,
dest="action",
help="Start the web interface on a web server.")
parser.add_option(
"-a",
"--api-server",
action="store_const",
const=Action.API_SERVER,
dest="action",
help="Start the control API.")
parser.add_option(
"-i",
"--i2c-check",
action="store_const",
const=Action.I2C_CHECK,
dest="action",
help="Check attached I2C devices.")
parser.add_option(
"-u",
"--ultrasonics",
action="store_const",
const=Action.ULTRASONICS_READ,
dest="action",
help="Poll all known ultrasonic sensors.")
parser.add_option(
"-s",
"--style",
action="store_const",
const=Action.STYLE_CHECKER,
dest="action",
help="Run the PEP8 style checker on all directories.")
parser.add_option(
"-e",
"--emergency-stop",
action="store_const",
const=Action.EMERGENCY_STOP,
dest="action",
help="Send a stop command to all motors. Does not prevent further commands from other processes.")
(options, args) = parser.parse_args()
action = options.action
if action == Action.KEYBOARD_CONTROL:
print "Starting keyboard control script."
check_output(
"python tiberius/testing/scripts/keyboard_control.py",
shell=True)
elif action == Action.KEYBOARD_CONTROL_COLLISION:
print "Starting keyboard collision control."
check_output("python tiberius/testing/scripts/ultras_control.py", shell=True)
elif action == Action.FULL_CONTROL:
print "Starting keyboard control with arm control."
check_output("python tiberius/testing/scripts/full_control.py", shell=True)
elif action == Action.RUN_TESTS:
print "Starting unit test suite."
check_output("python tiberius/testing/run_tests.py", shell=True)
elif action == Action.WEB_SERVER:
print "Starting the web server"
server = Popen(
"python tiberius/web-interface/manage.py runserver",
shell=True)
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
Popen.kill(server)
sys.exit()
elif action == Action.API_SERVER:
print "Starting the control API."
server = Popen("python tiberius/control_api/api.py", shell=True)
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
Popen.kill(server)
sys.exit()
elif action == Action.I2C_CHECK:
print "Checking I2C bus for devices"
result = check_output("i2cdetect -y 1", shell=True)
print result
elif action == Action.ULTRASONICS_READ:
print "Polling ultrasonic sensor distance values."
server = Popen(
"python tiberius/testing/scripts/manual_sensor_read.py",
shell=True)
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
Popen.kill(server)
sys.exit()
elif action == Action.STYLE_CHECKER:
print "Style Checking"
server = Popen(
"pep8 ./tiberius/",
shell=True)
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
Popen.kill(server)
sys.exit()
elif action == Action.EMERGENCY_STOP:
from tiberius.control.control import Control
print "Sending STOP to all motors."
c = Control()
c.motors.stop()