-
Notifications
You must be signed in to change notification settings - Fork 3
/
Menu.py
139 lines (122 loc) · 4.38 KB
/
Menu.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
#!/usr/bin/python3
import struct, binascii, Controller
def test():
Controller.manual_move(10)
def print_menu():
print('----- Control Menu ------')
print('1: Move To Coordinates')
print('2: Route To Coordinates')
print('3: Manual Movement')
print('4: Force Stop')
print('5: Charge')
print('6: Exit')
def manualMove():
print('Use arrow wasd for movement, hit "q" to complete')
while True:
command = input()
if command == 'w':
Controller.manual_move(10)
elif command == 's':
Controller.manual_move(11)
elif command == 'a':
Controller.manual_move(12)
elif command == 'd':
Controller.manual_move(13)
elif command == 'q':
break
def menu():
while True:
print_menu() # Prints Menu Options
while True:
# takes command input integer and validates
try:
command = int(input("Enter Command: "))
if 0 > command > 7:
raise ValueError
else:
break
except ValueError:
print('Enter an integer 1 - 5')
# ====================================================== Move To
if command == 1:
print('Selected Move To')
while True:
try:
x = int(input("Enter X Coordinate: "))
if len(str(x)) > 4:
raise TypeError
else:
break
except TypeError:
print('Coord not 4 bytes')
while True:
try:
y = int(input("Enter Y Coordinate: "))
if len(str(y)) > 4:
raise TypeError
else:
break
except TypeError:
print('Coord not 4 bytes')
while True:
try:
dir_command = input("Enter f -> forwards or b -> backwards: ")
if dir_command == 'f':
direction = 0
break
elif dir_command == 'b':
direction = 1
break
else:
raise TypeError
except TypeError:
print('enter "f" or "b"')
print('Moving to ' + str(x) + ' : ' + str(y))
Controller.move_to(x, y, direction)
# ====================================================== Route To
elif command == 2:
while True:
try:
x = int(input("Enter X Coordinate: "))
if len(str(x)) > 4:
raise TypeError
else:
break
except TypeError:
print('Coord not 4 bytes')
while True:
try:
y = int(input("Enter Y Coordinate: "))
if len(str(y)) > 4:
raise TypeError
else:
break
except TypeError:
print('Coord not 4 bytes')
print('Moving to ' + str(x) + ' : ' + str(y))
Controller.route_to(x, y)
print('Selected Route to')
# ====================================================== Manual Move
elif command == 3:
print('Manual Movement')
manualMove()
# ====================================================== STOP
elif command == 4:
print('Force Stop')
# ====================================================== Move to Charger
elif command == 5:
print('Charge')
Controller.move_to_charger()
# ====================================================== Program Quit
elif command == 6:
print('Exiting Program')
break
else:
print('validate Command')
if __name__ == '__main__':
sock = Controller.create_connection()
command = input("Do you want to run the test")
if command == 'y':
test()
else:
menu()