-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·125 lines (102 loc) · 2.19 KB
/
main.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
#!/usr/bin/env python
from flask import Flask, render_template, Response
import os
app = Flask(__name__)
from picar import PiCar
car = PiCar()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/camCentre')
def camCentre():
car.camCentre()
return ""
@app.route('/panL')
def panL():
car.panL()
return ""
@app.route('/panR')
def panR():
car.panR()
return ""
@app.route('/tiltD')
def tiltD():
car.tiltD()
return ""
@app.route('/tiltU')
def tiltU():
car.tiltU()
return ""
@app.route('/forward')
def forward():
car.forward()
return ""
@app.route('/reverse')
def reverse():
car.reverse()
return ""
@app.route('/left')
def left():
car.left()
return ""
@app.route('/right')
def right():
car.right()
return ""
@app.route('/leftL')
def leftL():
car.leftL()
return ""
@app.route('/rightL')
def rightL():
car.rightL()
return ""
@app.route('/leftU')
def leftU():
car.leftU()
return ""
@app.route('/rightU')
def rightU():
car.rightU()
return ""
@app.route('/stop')
def stop():
car.stop()
return ""
@app.route('/selfDrive')
def selfDrive():
car.selfDrive()
return ""
@app.route('/manualDrive')
def manualDrive():
car.manualDrive()
return ""
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed')
def video_feed():
if car.camera:
return Response(gen(car.camera),
mimetype='multipart/x-mixed-replace; boundary=frame')
else:
return ""
# ------------------------------------------------------------------------------------------
if __name__ == "__main__":
import os
pid=os.getpid()
with open('pid','w+') as pidfile:
pidfile.write('%s\n' % pid)
pidfile.close()
car()
from threading import Thread
## thread = Thread(target=lambda: app.run(threaded=True,host='0.0.0.0',port=8000))
try:
## thread.start()
## thread.join()
app.run(threaded=True,host='0.0.0.0',port=8000)
finally:
car.quit()
del car