-
Notifications
You must be signed in to change notification settings - Fork 8
/
voice_commands.py
39 lines (29 loc) · 1.23 KB
/
voice_commands.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
from multiprocessing import Queue
from flask import Flask, Response, request
import config
from communication.Serial import Serial
from navigation.RobotSerialCommandsConverter import RobotSerialCommandsConverter
from navigation.LongRunningCommand import LongRunningCommand
app = Flask(__name__)
serial = Serial(config.serial['port'], config.serial['baud_rate'])
serial.connect()
commands_converter = RobotSerialCommandsConverter()
communication_queue = Queue(maxsize=3)
process = LongRunningCommand(serial, communication_queue, 5000)
process.daemon = True
process.start()
@app.route("/api/motors", methods=["POST"])
# this is a naive implementation, will be refactored in the final release
def motors_command():
request_params = request.form
command = request_params['command']
angle = 90 if request_params['angle'] == 'None' else int(request_params['angle'])
if command == 'left':
angle = 90 - angle
elif command == 'right':
angle = 90 + angle
robot_command = commands_converter.get_steer_command(angle, 80, True)
communication_queue.put(robot_command, block=False)
return Response('', status=200, mimetype='application/json')
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8080)