-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
73 lines (58 loc) · 1.94 KB
/
test.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
# -*- coding: utf-8 -*-
from controller import *
from time import sleep, time
def read_process():
# Read the image identification numbers from the `resim_id_listesi` list and return them as a dictionary.
resim_id_listesi = [1, 2, 3, 4, 5]
# The `resim_id_listesi` list contains the image identification numbers.
operations = {
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
}
# The `operations` dictionary contains the functions that will be executed for each image identification number.
try:
reads = dict()
for i in range(5):
resim_id = resim_id_listesi[i]
reads[i] = resim_id
# Wait for the function to complete.
if resim_id in operations:
sleep(int(operations[resim_id]))
else:
print("Geersiz resim_id:", resim_id)
return reads
except KeyboardInterrupt:
raise
def main():
# Initialize the controller.
controller_init()
# Enter an infinite loop.
while True:
# Get the image identification numbers.
reads = read_process()
# Iterate over the image identification numbers.
for i in reads:
# Execute the corresponding function.
if reads[i] == "1":
controller_forward()
elif reads[i] == "2":
controller_right()
elif reads[i] == "3":
controller_backward()
elif reads[i] == "4":
controller_left()
elif reads[i] == "5":
# Print the reads dictionary.
print("reads:", reads)
elif reads[i] == "6":
# Close the controller.
controller_close()
exit(0)
else:
# Print an error message.
print("Invalid option. Please try again.")
if __name__ == "__main__":
main()