-
Notifications
You must be signed in to change notification settings - Fork 1
/
Final2.py
148 lines (117 loc) · 4.17 KB
/
Final2.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
140
141
142
143
144
145
146
147
148
import telepot
import telebot
import time
import sys
import RPi.GPIO as GPIO
def Setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(3,GPIO.IN) # IR
GPIO.setup(4,GPIO.OUT) # Wheel1
GPIO.setup(14,GPIO.OUT) # Wheel 1
GPIO.setup(17,GPIO.OUT) #Wheel 2
GPIO.setup(18,GPIO.OUT) # Wheel 2
#GPIO.setup(24,GPIO.IN)#echo1
#GPIO.setup(23,GPIO.OUT)#Trig1
#GPIO.setup(16,GPIO.OUT)#Servo Motor
GPIO.setup(20,GPIO.OUT)#Trigger2
GPIO.setup(21,GPIO.IN)#Echo2
#GPIO.setup(19,GPIO.OUT) #Lid Motor
#GPIO.setup(26,GPIO.OUT) #Lid Motor
Setup()
bot= telepot.Bot('812318556:AAEcVpsMRR9HE9Ee8TW3YipykpgnKU1GGL4')
def Dist():
GPIO.output(20, False)
time.sleep(2)
print( "Calculating distance")
GPIO.output(20, True)
time.sleep(0.00001)
GPIO.output(20, False)
while GPIO.input(21)==0:
pulse_start_time = time.time()
while GPIO.input(21)==1:
pulse_end_time = time.time()
pulse_duration = pulse_end_time - pulse_start_time
distance = round(pulse_duration * 17150, 2)
return distance
d= Dist()
print(d)
while(1):
a=bot.getUpdates()[-1]
time.sleep(1)
y=(a['message']['text'])
if y == "Come" or y== "COME"or y== "come":
bot.sendMessage(680782323,'there in a minute')
print(y)
time.sleep(3)
d= Dist()
print(d)
#"Move Forward"
if( GPIO.input(3)==False and d>30):
GPIO.output(4,True)
GPIO.output(14,False)
GPIO.output(17,True)
GPIO.output(18,False)
elif (GPIO.input(3)==False and d<30):
GPIO.output(4,True) #STOPS FOR 1 SEC IF OBSTACLE
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,True)
time.sleep(1)
GPIO.output(4,True) #TAKES LEFT
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,False)
time.sleep(2)
GPIO.output(4,True) #Forward
GPIO.output(14,False)
GPIO.output(17,True)
GPIO.output(18,False)
elif(GPIO.input(3)==True):
GPIO.output(4,True) #stop
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,True)
elif y== "go" or y== "Go" or y== "GO" or y== "Nikal Lavde" or y== "NIKAL LAVDE" or y== "nikal lavde" or y== "NIKAL LAWDE" or y== "Nikal Lawde" or y== "nikal lawde" or y== "Nikal lawde":
bot.sendMessage(680782323,'Thik hai Lavde')
print(y)
time.sleep(3)
if(GPIO.input(3)==True):
GPIO.output(4,True) #TAKE U TURN
GPIO.output(14,False)
GPIO.output(17,True)
GPIO.output(18,True)
time.sleep(3)
d= Dist()
print(d)
if( GPIO.input(3)==False and d>30):
GPIO.output(4,True)
GPIO.output(14,False)
GPIO.output(17,True)
GPIO.output(18,False)
elif (GPIO.input(3)==False and d<30):
GPIO.output(4,True) #STOPS FOR 1 SEC IF OBSTACLE
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,True)
time.sleep(1)
GPIO.output(4,True) #TAKES LEFT
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,False)
time.sleep(2)
GPIO.output(4,True) #Forward
GPIO.output(14,False)
GPIO.output(17,True)
GPIO.output(18,False)
elif(GPIO.input(3)==True):
GPIO.output(4,True) #stop
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,True)
else:
print(y)
GPIO.output(4,True) #stop
GPIO.output(14,True)
GPIO.output(17,True)
GPIO.output(18,True)