forked from Euleeee/6RUSRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (42 loc) · 1.48 KB
/
main.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
import logging
import os
from sys import argv
import RPi.GPIO as GPIO
from button import EXIT_SHUTDOWN
from runtime import Runtime
# main program if this file get executed
if __name__ == '__main__':
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)-15s %(threadName)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s'
)
try:
robot_type = argv[1]
except IndexError:
logging.exception("Need to supply robot type as command-line argument")
raise
app = Runtime(robot_type)
exit_code = None
try:
app_initialized = True
app.loop()
except KeyboardInterrupt:
# shutdown python program gently
logging.exception("Stopped with KeyboardInterrupt!")
except SystemExit as e:
# shutdown via button
logging.exception("Stopped via button press")
app.program_stopped.set()
app.lcd.print_status('Shutting down...')
exit_code = e.code
except Exception as e:
logging.exception(e)
finally:
app.program_stopped.set()
# cleanup GPIOs (to avoid warning on next startup)
GPIO.cleanup()
if exit_code == EXIT_SHUTDOWN:
os.system("sudo shutdown now")
# Exiting message
logging.info("6-RUS program was terminated due to user-input or an error (Please wait ca. 5s)")
logging.info("Please start the program again to control the robot again!")