-
Notifications
You must be signed in to change notification settings - Fork 2
/
obstacle avoid robo car using ultrasonic sensor.py
139 lines (92 loc) · 2.06 KB
/
obstacle avoid robo car using ultrasonic sensor.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
import RPi.GPIO as io
import time
from time import sleep
io.setwarnings(False)
io.setmode(io.BOARD)
TRIG1=3
ECHO1=5
TRIG2=7
ECHO2=8
TRIG3=10
ECHO3=11
TRIG4=12
ECHO4=13
maximum=50
minimum=5
io.setup(TRIG1,io.OUT)
io.setup(TRIG2,io.OUT)
io.setup(TRIG3,io.OUT)
io.setup(TRIG4,io.OUT)
io.setup(ECHO1,io.IN)
io.setup(ECHO2,io.IN)
io.setup(ECHO3,io.IN)
io.setup(ECHO4,io.IN)
def ultra1():
io.output(TRIG1,False)
sleep(0.2)
io.output(TRIG1,True)
sleep(0.00001)
io.output(TRIG1,False)
while io.input(ECHO1)==0:
pulse_start=time.time()
while io.input(ECHO1)==1:
pulse_end=time.time()
t1=pulse_end-pulse_start
d1= t1 * 17150
d1=round(d1,2)
return d1
def ultra2():
io.output(TRIG2,False)
sleep(0.2)
io.output(TRIG2,True)
sleep(0.00001)
io.output(TRIG2,False)
while io.input(ECHO2)==0:
pulse_start=time.time()
while io.input(ECHO2)==1:
pulse_end=time.time()
t2=pulse_end-pulse_start
d2= t2 * 17150
d2=round(d2,2)
return d2
def ultra3():
io.output(TRIG3,False)
sleep(0.2)
io.output(TRIG3,True)
sleep(0.00001)
io.output(TRIG3,False)
while io.input(ECHO3)==0:
pulse_start=time.time()
while io.input(ECHO3)==1:
pulse_end=time.time()
t3=pulse_end-pulse_start
d3= t3 * 17150
d3=round(d3,2)
print d3
def ultra4():
io.output(TRIG4,False)
sleep(0.2)
io.output(TRIG4,True)
sleep(0.00001)
io.output(TRIG4,False)
while io.input(ECHO4)==0:
pulse_start=time.time()
while io.input(ECHO4)==1:
pulse_end=time.time()
t4=pulse_end-pulse_start
d4= t4 * 17150
d4=round(d4,2)
print d4
while True:
c=ultra1()
d=ultra2()
e=ultra3()
f=ultra4()
if (c<maximum & c>minimum):
print " c side Safe"
if (d<maximum & d>minimum):
print " d side Safe"
if (e<maximum & e>minimum):
print " e side Safe"
if (f<maximum & f>minimum):
print " f side Safe"