-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·74 lines (55 loc) · 1.97 KB
/
manage.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
#! /usr/bin/env python
''' Main input of program, cli, etc... '''
import os
import argparse
import glob
import importlib
from autorc.config import config
def get_profiles():
''' List all vehicle profiles '''
return [
os.path.basename(path)[:-3]
for path in glob.glob(os.path.join(config.PROFILES_ROOT, "*.py"))
if os.path.isfile(path) and not path.endswith('__init__.py')
]
''' ============ ACTIONS ============ '''
def list_profile(args):
''' Print all vehicle profiles '''
print("Available profiles:", ','.join(get_profiles()))
print("Usage: ./manage.py -p <profile_name> start")
def reset_servo(args):
''' Set all servos to 90 degree (middle) position '''
print('Set servos to 90 degree...')
from autorc.picar3.Servo import Servo
for i in range(16): # 16 pins
servo = Servo(i)
servo.setup()
servo.write(90)
def start(args):
''' Run a vehicle profile '''
profile = args.profile
mod = importlib.import_module('autorc.profiles.' + profile)
if not hasattr(mod, 'vehicle'):
print('Profile', profile, 'does not has vehicle instance')
else:
print('Start', profile, 'vehicle.')
getattr(mod, 'vehicle').start()
ALLOWED_ACTIONS = {
'reset-servo': reset_servo,
'list-profile': list_profile,
'start': start
}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Noahcar cli.')
parser.add_argument('-p', '--profile', default='default',
choices=get_profiles(), dest='profile',
help='Vehicle profile to load')
parser.add_argument('action', help='Action to run', nargs='?')
args = parser.parse_args()
if not args.action or args.action not in ALLOWED_ACTIONS:
parser.print_help()
print("Available actions:")
for action, method in ALLOWED_ACTIONS.items():
print(' ', action, method.__doc__)
else:
ALLOWED_ACTIONS[args.action](args)