forked from robovero/python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher.py
139 lines (128 loc) · 2.4 KB
/
launcher.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
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
''' Use to lauch robovero example, need ttyACM0 to be robovero
'''
import sys
from examples import \
IMU,\
adc,\
callback,\
can_recv,\
can_send,\
clockout,\
DSP,\
gpio,\
mcpwm,\
piezo,\
servo,\
stepper,\
uart_recv,\
uart_send,\
range_finder,\
mcpwm_brushless,\
servo_driver,\
aerothing,\
script
EXAMPLES=[
'IMU',
'adc',
'callback',
'can_recv',
'can_send',
'clockout',
'DSP',
'gpio',
'mcpwm',
'piezo',
'servo',
'stepper',
'uart_recv',
'uart_send',
'range_finder',
'mcpwm_brushless',
'servo_driver',
'aerothing',
'script',
]
def parse_argv(argv):
command = None
option = None
try:
command = str(argv[1])
option = str(argv[2])
except:
pass
if command == 'run':
run_example(option)
elif command == 'list':
list_examples()
else:
help()
exit()
def run_example(example):
example_id = -1
if not example:
print 'Please provide an example, type help for details'
return
elif example.isdigit():
example_id = int(example)
elif example in EXAMPLES:
example_id = EXAMPLES.index(example)
else:
print '''Can't find example'''
return
if example_id is 0:
print 'call IMU'
IMU.run()
elif example_id is 1:
print 'call adc'
adc.run()
elif example_id is 2:
callback.run()
elif example_id is 3:
can_recv.run()
elif example_id is 4:
can_send.run()
elif example_id is 5:
clockout.run()
elif example_id is 6:
DSP.run()
elif example_id is 7:
gpio.run()
elif example_id is 8:
mcpwm.run()
elif example_id is 9:
piezo.run()
elif example_id is 10:
servo.run()
elif example_id is 11:
stepper.run()
elif example_id is 12:
uart_recv.run()
elif example_id is 13:
uart_send.run()
elif example_id is 14:
range_finder.run()
elif example_id is 15:
mcpwm_brushless.run()
elif example_id is 16:
servo_driver.run()
elif example_id is 17:
aerothing.run()
elif example_id is 18:
script.run()
def list_examples():
for i in range(len(EXAMPLES)):
example_id = str(i)
example_name = EXAMPLES[i]
print example_id, example_name
def help():
help_text = '''\
Options:
list -- Show a list of examples
run NAME_OF_EXAMPLE -- Run example by name
run ID_OF_EXAMPLE -- Run example by id
help -- Show this help\
'''
print help_text
if __name__ == '__main__':
argv = sys.argv
parse_argv(argv)