-
Notifications
You must be signed in to change notification settings - Fork 51
/
drive_server.py
124 lines (97 loc) · 2.29 KB
/
drive_server.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
#!/usr/bin/python
from flask import Flask, render_template, request, Response, send_file
from camera_pi import Camera
import wheels
import speaker
import autonomous
import os
app = Flask(__name__)
@app.route("/")
def main():
return render_template('index.html')
@app.route('/forward')
def forward():
wheels.forward(200, 3)
return ''
@app.route('/backward')
def backward():
wheels.backward(200, 3)
return ''
@app.route('/shake')
def shake():
wheels.left(200, 0.2)
wheels.right(200, 0.2)
return ''
@app.route('/left')
def left():
wheels.left(200, 3)
return ''
@app.route('/right')
def right():
wheels.right(200, 3)
return ''
@app.route('/f')
def f():
wheels.forward(200)
return ''
@app.route('/b')
def b():
wheels.backward(200)
return ''
@app.route('/r')
def r():
wheels.right(200)
return ''
@app.route('/l')
def l():
wheels.left(200)
return ''
@app.route('/stop')
def stop():
wheels.stop()
return ''
@app.route('/latest.jpg')
def latest():
filename = 'images/latest_img.jpg'
return send_file(filename, mimetype='image/jpg')
@app.route('/drive')
def drive():
time = 10
if 'time' in request.args:
time = int(request.args.get('time'))
autonomous.autodrive(time)
return ''
@app.route('/say')
def say():
text = request.args.get('text')
speaker.say(text)
return ''
@app.route('/data')
def data():
img_num = request.args.get('i')
if img_num is None:
filename = 'images/latest_data'
else:
filename = 'images/data'+img_num
f = open(filename, 'r')
data = f.read()
return data
@app.route('/img_rec')
def img_rec():
wheels.stop()
# os.system('python image.py')
return ''
def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
time.sleep(0.5)
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == "__main__":
app.run()