Skip to content

Commit 002f135

Browse files
committed
Works with wonkus and wallace now
1 parent 758d60a commit 002f135

6 files changed

+80
-69
lines changed

drive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ def setSpeed():
206206

207207
return ''
208208

209-
@app.route('/img')
209+
@app.route('/latest.jpg')
210210
def latest():
211-
img_num = request.args.get('i')
212-
if img_num is None:
213-
filename = 'images/latest_img.jpg'
214-
else:
215-
filename = 'images/img'+img_num+'.jpg'
211+
# img_num = request.args.get('i')
212+
# if img_num is None:
213+
filename = 'images/latest_img.jpg'
214+
# else:
215+
# filename = 'images/img'+img_num+'.jpg'
216216

217217
return send_file(filename, mimetype='image/jpg')
218218

drive_safe.py

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def do(cmd):
1818

1919
GPIO.setmode(GPIO.BCM)
2020

21-
TRIG = [23, 5, 22]
22-
ECHO = [24, 6, 27]
21+
TRIG = [23, 17, 22]
22+
ECHO = [24, 18, 27]
2323

2424

2525
def setup():
@@ -156,7 +156,7 @@ def right(speed, dur):
156156

157157

158158
def getAttention():
159-
with open('../python-mindwave-mobile/ATTENTION', 'r') as f:
159+
with open('../python-mindave-mobile/ATTENTION', 'r') as f:
160160
read_data = f.read()
161161
print("Read Speed: " + read_data)
162162

@@ -180,59 +180,59 @@ def getAttention():
180180
maxTurnCount = 3;
181181

182182
while(1==1):
183-
while True:
184-
s = getAttention();
185-
print "Speed "+str(s)
186-
if s > 0:
187-
break
188-
setSpeed(0)
189-
time.sleep(0.2)
183+
print("driving!")
184+
185+
# while True:
186+
# s = getAttention();
187+
# print "Speed "+str(s)
188+
# if s > 0:
189+
# break
190+
# setSpeed(0)
191+
# time.sleep(0.2)
190192

191-
mind = 1000
192-
d=[]
193-
194-
for i in range(3):
195-
d.append( distance(i));
196-
if d[i] < mind:
197-
mind = d[i]
198-
print(d[i]);
199-
200-
#print(d)
201-
#print("Min d " + str(mind))
202-
203-
if (mind<6 and stopped==True and turning==True):
204-
do('echo "backing up." | flite ')
205-
backward(100, 1);
206-
elif (turnCount > maxTurnCount):
207-
do('echo "backing up." | flite ')
208-
backward(100, 1);
209-
turnCount = 0;
210-
elif (mind>=THRESH and stopped==True):
211-
stopped=False;
212-
turning = False;
213-
gof();
214-
turnCount = 0
215-
216-
elif (mind<THRESH and stopped==False):
217-
stopped=True;
218-
elif (mind<THRESH and stopped==True):
219-
220-
if (turning==False):
221-
stop();
222-
turning=True
223-
else:
224-
turnCount+=1
225-
226-
if d[2] > d[0]:
227-
do('echo "turning left." | flite ')
228-
left(100, 0.7);
229-
else:
230-
do('echo "turning right." | flite ')
231-
right(100, 0.7);
232-
233-
time.sleep(0.3);
234-
stopped=True
235-
elif (turning==False): # robot is moving happily
236-
237-
newSpd = getAttention();
238-
setSpeed(newSpd);
193+
mind = 1000
194+
d=[]
195+
196+
for i in range(3):
197+
d.append( distance(i));
198+
if d[i] < mind:
199+
mind = d[i]
200+
print(d[i]);
201+
202+
print(d)
203+
print("Min d " + str(mind))
204+
205+
if (mind<6 and stopped==True and turning==True):
206+
do('echo "backing up." | flite ')
207+
backward(255, 1)
208+
elif (turnCount > maxTurnCount):
209+
do('echo "backing up." | flite ')
210+
backward(255, 1);
211+
turnCount = 0;
212+
elif (mind>=THRESH and stopped==True):
213+
stopped=False;
214+
turning = False;
215+
gof();
216+
turnCount = 0
217+
elif (mind<THRESH and stopped==False):
218+
stopped=True;
219+
220+
elif (mind<THRESH and stopped==True):
221+
if (turning==False):
222+
stop();
223+
turning=True
224+
else:
225+
turnCount+=1
226+
227+
if d[2] > d[0]:
228+
do('echo "turning left." | flite ')
229+
left(255, 0.5);
230+
else:
231+
do('echo "turning right." | flite ')
232+
right(255, 0.5);
233+
234+
time.sleep(0.3);
235+
stopped=True
236+
# elif (turning==False): # robot is moving happily
237+
#newSpd = getAttention();
238+
#setSpeed(newSpd);

image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def classify(n):
2020
do('echo "I\'m thinking." | flite')
2121
do('cp /dev/shm/mjpeg/cam.jpg '+imageFile);
2222
do('ln -f '+imageFile+' '+latestImage);
23-
do('python run_and_parse_inception.py '+imageFile+ " " +dataFile)
23+
do('bash run_and_parse_inception.sh '+imageFile+ " " +dataFile)
2424

2525
do('ln -f '+dataFile+' '+latestData);
2626

run_and_parse_inception.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
def do(cmd):
1111
print(cmd)
12-
p =subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
12+
p =subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1313
for line in p.stdout.readlines():
1414
print line
1515

1616
retval = p.wait()
1717

18-
do('( cd /home/pi/tensorflow && ./label_image --image=../robot/'+imageFile+' > ../robot/raw.output )' )
18+
do('( cd /home/pi/tensorflow && ./label_image --image=../robot/'+imageFile+' ) &> ../robot/raw.output ' )
1919

20-
do('tail -5 ../robot/raw.output | tail -5 ../tensorflow/t | cut -d"]" -f2 | cut -d"(" -f1 > ' + dataFile)
20+
do('tail -5 raw.output | cut -d"]" -f2 | cut -d"(" -f1 > ' + dataFile)

run_and_parse_inception.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash
2+
3+
( cd /home/pi/tensorflow && ./label_image --image=../robot/$1) &> ../robot/raw.output
4+
tail -5 raw.output | cut -d"]" -f2 | cut -d"(" -f1 > $2

sonar.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import RPi.GPIO as GPIO
22
import sys
33
import time
4+
import atexit
5+
6+
# recommended for auto-disabling motors on shutdown!
7+
def turnOffGPIO():
8+
GPIO.cleanup()
9+
10+
atexit.register(turnOffGPIO)
411

512
GPIO.setmode(GPIO.BCM)
613

@@ -40,5 +47,5 @@
4047

4148
print "Distance:",distance,"cm"
4249

43-
GPIO.cleanup()
50+
4451

0 commit comments

Comments
 (0)