-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
70 lines (60 loc) · 1.56 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/python
# Python AR.Drone control
# Copyright (C) 2016 LegoNigel <[email protected]>
import libardrone
from drone_control import DroneController
from video import Video
from wiimote import InputWiimote
from keyboard import InputKeyboard
from balanceboard import InputBalanceBoard
from wiimoteAC import InputWiimoteAC
from time import sleep
import signal
import sys
def main():
"""Main program"""
controller = DroneController()
controller.start()
input_sources = []
input_sources.append(InputWiimote())
input_sources.append(InputKeyboard("Keyboard"))
input_sources.append(InputBalanceBoard())
input_sources.append(InputWiimoteAC())
for source in input_sources:
if hasattr(source, "makeConnection"):
source.makeConnection()
else:
print "This input source has not makeConnection method you dumb coder!"
print source
if not hasattr(source, "determine"):
print "{} has not function determine, exiting".format(source)
exit(1)
running = True
try:
while running:
print ".",
for source in input_sources:
command = source.determine()
if command == 'reset':
running = False
if command:
print "doing {}".format(command)
controller.do_command(command)
sleep(0.01) #sleep 10 ms
except (KeyboardInterrupt, SystemExit):
pass
for source in input_sources:
if hasattr(source, "stop"):
source.stop()
controller.do_command("reset")
controller.do_command("halt")
print "Done!"
quit()
if __name__ == '__main__':
try:
#vid = Video('Thread Video')
#vid.start()
main()
except Exception:
#vid.stop()
sys.exit()