Skip to content

Commit 7ecf45d

Browse files
committed
bot code
1 parent 4c875cb commit 7ecf45d

19 files changed

+528
-0
lines changed

robot_src/ARLO1.jpg

41.6 KB
Loading

robot_src/app.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import socket
2+
import bot
3+
from flask import Flask, render_template, request, redirect, url_for, make_response
4+
import RPi.GPIO as gpio
5+
gpio.setmode(gpio.BOARD)
6+
gpio.setwarnings(False)
7+
8+
9+
# Get server ip
10+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
11+
s.connect(("8.8.8.8", 80))
12+
server_ip = s.getsockname()[0]
13+
s.close()
14+
15+
app = Flask(__name__)
16+
17+
18+
@app.route('/')
19+
def index():
20+
21+
data = bot.dht()
22+
humid = data[0]
23+
temp = data[1]
24+
25+
return render_template('index.html', server_ip=server_ip, temperature=temp, humidity=humid)
26+
27+
28+
@app.route('/<changepin>', methods=['POST'])
29+
def reroute(changepin):
30+
bot.init()
31+
32+
changePin = int(changepin)
33+
34+
if changePin == 1:
35+
# motors.turnLeft()
36+
bot.left()
37+
elif changePin == 2:
38+
bot.forward()
39+
# motors.forward()
40+
elif changePin == 3:
41+
bot.right()
42+
# motors.turnRight()
43+
elif changePin == 4:
44+
bot.backward()
45+
# motors.backward()
46+
elif changePin == 5:
47+
gpio.cleanup()
48+
else:
49+
print("Wrong command")
50+
51+
response = make_response(redirect(url_for('index')))
52+
return(response)
53+
54+
55+
app.run(debug=True, host='0.0.0.0', port=8000)

robot_src/arlo_art__.jpg

346 KB
Loading

robot_src/arlo_bokeh.jpg

68.7 KB
Loading

robot_src/bot.py

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import RPi.GPIO as gpio
2+
import time
3+
import sys
4+
import Tkinter as tk
5+
import random
6+
import Adafruit_DHT
7+
import time
8+
9+
DHT_SENSOR = Adafruit_DHT.DHT11
10+
DHT_PIN = 17
11+
12+
gpio.setmode(gpio.BOARD)
13+
gpio.setwarnings(False)
14+
15+
16+
def init() :
17+
gpio.setmode(gpio.BOARD)
18+
gpio.setup(31, gpio.OUT)
19+
gpio.setup(33, gpio.OUT)
20+
gpio.setup(35, gpio.OUT)
21+
gpio.setup(37, gpio.OUT)
22+
23+
24+
def backward() :
25+
#gpio.output(31, False)
26+
#gpio.output(33, False)
27+
gpio.output(35, True)
28+
gpio.output(37, False)
29+
time.sleep(1)
30+
gpio.output(35, False)
31+
#gpio.cleanup()
32+
33+
34+
def forward() :
35+
#gpio.output(31, False)
36+
#gpio.output(33, False)
37+
gpio.output(35, False)
38+
gpio.output(37, True)
39+
time.sleep(1)
40+
gpio.output(37, False)
41+
#gpio.cleanup()
42+
43+
44+
def right() :
45+
gpio.output(31, True)
46+
gpio.output(33, False)
47+
#time.sleep(0.2)
48+
#gpio.output(35, False)
49+
#gpio.output(37, True)
50+
#time.sleep(tf)
51+
#gpio.cleanup()
52+
53+
def left() :
54+
gpio.output(31, False)
55+
gpio.output(33, True)
56+
#time.sleep(0.2)
57+
#gpio.output(35, False)
58+
#gpio.output(37, True)
59+
#time.sleep(tf)
60+
#gpio.cleanup()
61+
62+
63+
64+
65+
def dht(): #gets temp and humid returns [humid,temp]
66+
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
67+
68+
print([humidity,temperature])
69+
return [humidity,temperature]
70+
71+
def distance(): # gets obstacle distace (returns float)
72+
try:
73+
TRIG = 16
74+
ECHO = 18
75+
76+
gpio.setup(TRIG,gpio.OUT)
77+
gpio.setup(ECHO,gpio.IN)
78+
79+
gpio.output(TRIG, True)
80+
time.sleep(0.00001)
81+
gpio.output(TRIG, False)
82+
83+
while gpio.input(ECHO) == False:
84+
start = time.time()
85+
86+
while gpio.input(ECHO) == True:
87+
end = time.time()
88+
89+
sig_time = end-start
90+
#CM:
91+
distance = sig_time/ 0.000058
92+
#print('Distance: {} centimeters'.format(distance))
93+
gpio.cleanup()
94+
95+
return distance
96+
except:
97+
print("except")
98+
return 10
99+
gpio.cleanup()
100+
101+
def check(tf):
102+
init()
103+
dist=distance()
104+
105+
if dist<40:
106+
print("Dead",)
107+
108+
x=random.randrange(0,2)
109+
110+
if(x==0):
111+
init()
112+
left(tf)
113+
backward(tf)
114+
else:
115+
init()
116+
right(tf)
117+
backward(tf)
118+
119+
dist=distance()
120+
if dist<15:
121+
init()
122+
backward(1)
123+
init()
124+
forward(tf)
125+
126+
127+
def autonomy():
128+
tf=0.03
129+
130+
x=random.randrange(0,3)
131+
132+
if x==0:
133+
for y in range(30):
134+
check(tf)
135+
init()
136+
forward(0.2)
137+
elif(x==1):
138+
for y in range(30):
139+
check(tf)
140+
init()
141+
left(tf)
142+
forward(0.2)
143+
elif(x==2):
144+
for y in range(30):
145+
check(tf)
146+
init()
147+
right(tf)
148+
forward(tf)
149+
150+
151+
152+
153+
154+
'''def key_input(event) :
155+
init()
156+
print 'Key : ',event.char
157+
key_press = event.char
158+
sleep_time = 0.025
159+
160+
if key_press.lower() == 'w':
161+
forward()
162+
elif key_press.lower() == 's':
163+
backward()
164+
elif key_press.lower() == 'a':
165+
left()
166+
elif key_press.lower() == 'd':
167+
right()
168+
elif key_press.lower() == 'z':
169+
for i in range(30):
170+
autonomy()
171+
elif key_press.lower() == 'x':
172+
gpio.cleanup()
173+
sys.exit()
174+
else:
175+
gpio.cleanup()
176+
177+
178+
command = tk.Tk()
179+
command.bind('<KeyPress>',key_input)
180+
command.mainloop()'''
181+
182+

robot_src/bot.pyc

3.33 KB
Binary file not shown.

robot_src/bw.jpg

221 KB
Loading
5.17 MB
Loading
3.1 MB
Loading
2.92 MB
Loading
3.51 MB
Loading

robot_src/media/app controls.jpg

376 KB
Loading

robot_src/media/video.mp4

5.4 MB
Binary file not shown.

robot_src/static/img/forward.svg

+46
Loading

robot_src/static/img/left.svg

+46
Loading

robot_src/static/img/reverse.svg

+46
Loading

0 commit comments

Comments
 (0)