-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi.py
211 lines (107 loc) · 3.21 KB
/
pi.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import RPi.GPIO as GPIO
import time
from time import sleep
import face_recognition
from os import system
import database
lift1=[3,5,7,11]
lift2=[13,15,19,21]
cur_floor_lift1=1
cur_floor_lift2=1
def on(pin):
GPIO.output(pin,GPIO.HIGH)
def off(pin):
GPIO.output(pin,GPIO.LOW)
def close_all():
off(lift1[0])
off(lift2[0])
off(lift1[1])
off(lift2[1])
off(lift1[2])
off(lift2[2])
off(lift1[3])
off(lift2[3])
def initialise():
on(lift1[0])
on(lift2[0])
def move_lift1(cur_floor_lift1,target_floor):
if cur_floor_lift1==target_floor:
return
if cur_floor_lift1<target_floor:
dir=1
else:
dir=-1
for i in range(cur_floor_lift1,target_floor,dir):
off(lift1[i-1])
# sleep(2)
print "Lift 1 :" +str(i+dir)
on(lift1[i+dir-1])
cur_floor_lift1=i+dir
sleep(3)
return cur_floor_lift1
def move_lift2(cur_floor_lift2,target_floor):
if cur_floor_lift2 == target_floor:
return
if cur_floor_lift2 < target_floor:
dir = 1
else:
dir = -1
for i in range(cur_floor_lift2, target_floor, dir):
off(lift2[i - 1])
print "Lift 2 :" + str(i + dir)
on(lift2[i + dir - 1])
cur_floor_lift2=i+dir
sleep(3)
return cur_floor_lift2
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# stop warnings
GPIO.setwarnings(False)
# set up GPIO output channel
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
close_all()
initialise()
while(1):
system("raspistill -o Img.png")
user=face_recognition.recognize("Img.png")
if user==-2:
print "LIFT is Idle No face Detected"
continue
entry=int(raw_input("Enter Current Floor No :"))
if user==-1:
# print "AAya"
exit=int(raw_input("Enter Destination :"))
user=int(time.time())
database.insert(user,entry,exit)
if abs(entry-cur_floor_lift1)<abs(entry-cur_floor_lift2):
cur_floor_lift1= move_lift1(cur_floor_lift1,entry)
cur_floor_lift1= move_lift1(entry,exit)
else:
cur_floor_lift2= move_lift2(cur_floor_lift2,entry)
cur_floor_lift2= move_lift2(entry,exit)
face_recognition.post("Img.png",user)
elif database.find(user,entry)==-1:
# print "Pss"
exit = int(raw_input("Enter Destination :"))
database.insert(user, entry, exit)
if abs(entry - cur_floor_lift1) < abs(entry - cur_floor_lift2):
cur_floor_lift1= move_lift1(cur_floor_lift1,entry)
cur_floor_lift1= move_lift1(entry,exit)
else:
cur_floor_lift2= move_lift2(cur_floor_lift2,entry)
cur_floor_lift2= move_lift2(entry,exit)
else:
exit=database.find(user,entry)
if abs(entry - cur_floor_lift1) < abs(entry - cur_floor_lift2):
cur_floor_lift1= move_lift1(cur_floor_lift1,entry)
cur_floor_lift1= move_lift1(entry,exit)
else:
cur_floor_lift2= move_lift2(cur_floor_lift2,entry)
cur_floor_lift2= move_lift2(entry,exit)