-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathavoidObstacle.py
50 lines (42 loc) · 1.01 KB
/
avoidObstacle.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
from buzzer import Buzzer
from motor import Forward, Backward, Left, Right, Stop
from time import sleep
from ultraSonic import Distance
from servo import ultraSonicLeft, ultraSonicPosition, ultraSonicRight
while True:
d = Distance()
print('Front Distance is', d, 'cm')
if d < 10.0:
Stop()
Buzzer()
sleep(0.5)
Backward(20)
sleep(0.8)
Stop()
sleep(0.3)
ultraSonicLeft()
sleep(0.5)
L = Distance()
print('Left Distance is', L, 'm')
sleep(0.5)
ultraSonicPosition()
sleep(0.5)
ultraSonicRight()
sleep(0.5)
R = Distance()
print('Right Distance is', R, 'm')
sleep(0.5)
ultraSonicPosition()
sleep(0.5)
if L > R:
Left(60)
sleep(0.3)
Stop()
sleep(0.5)
else:
Right(60)
sleep(0.3)
Stop()
sleep(0.5)
else:
Forward(20)