-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTheMazeRunner.py
More file actions
66 lines (53 loc) · 1.77 KB
/
TheMazeRunner.py
File metadata and controls
66 lines (53 loc) · 1.77 KB
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
#!/usr/bin/env/ python3
from ev3dev2.sensor.lego import UltrasonicSensor
from ev3dev2.motor import MoveTank, OUTPUT_A, OUTPUT_D
from ev3dev2.button import Button
import time
from ev3dev2.sensor.lego import ColorSensor
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)5s: %(message)s')
log = logging.getLogger(__name__)
cs = ColorSensor()
us = UltrasonicSensor()
tp = MoveTank(OUTPUT_A, OUTPUT_D)
button = Button()
try:
while not button.any():
#white line and turn
tp.on(left_speed = 50, right_speed = 50)
time.sleep(1.5)
while not button.any():
CS = cs.reflected_light_intensity
log.info(CS)
if CS > 15:
break
tp.on_for_rotations(-50, 50, 0.65)
#yellow line and turn
tp.on(left_speed = 50, right_speed = 50)
time.sleep(1.5)
while not button.any():
if cs.reflected_light_intensity > 15:
break
tp.on_for_rotations(50, -50, 0.65)
#Cabinet obstruction
while not button.any():
tp.on(left_speed = 50, right_speed = 50)
dist = int( us.distance_centimeters_continuous)
log.info(dist)
if dist < 33:
break
tp.on_for_rotations(-50, 50, 0.65)
#Finish line
tp.on(left_speed = 50, right_speed = 50)
time.sleep(1)
while not button.any():
if cs.reflected_light_intensity > 15:
break
tp.on(left_speed = 0, right_speed = 0)
log.info("Done")
break
log.info("Complete")
except(KeyboardInterrupt):
print('interrupt')
tp.on(left_speed = 0, right_speed = 0)