-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual_controls.py
65 lines (59 loc) · 1.58 KB
/
manual_controls.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
import getch
from threading import Thread, Lock
from movements import *
from time import sleep
lock = Lock()
user_input = ''
done = False
def get_user_input():
global done
global user_input
while not done:
reading_input = getch.getch()
if reading_input == ' ':
lock.acquire()
done = True
lock.release()
else:
reading_input = reading_input.lower()
lock.acquire()
user_input = reading_input
lock.release()
def execute_user_input():
global done
global user_input
while not done:
lock.acquire()
executing_input = user_input
user_input = ''
lock.release()
print('user input executer')
print(executing_input)
if executing_input == 'w':
print(executing_input)
if executing_input == 'w':
move('forward')
elif executing_input == 's':
move('reverse')
elif executing_input == 'a':
turn('left')
elif executing_input == 'd':
turn('right')
elif executing_input == 'u':
turn('u_turn')
elif executing_input == 'r':
lift('up')
elif executing_input == 'f':
lift('down')
elif executing_input == '':
lift('')
move('')
turn('')
sleep(0.1)
executing_input = ''
thread_reader = Thread(target=get_user_input)
thread_executer = Thread(target=execute_user_input)
thread_reader.start()
thread_executer.start()
thread_reader.join()
thread_executer.join()