-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
59 lines (47 loc) · 1.17 KB
/
server.py
File metadata and controls
59 lines (47 loc) · 1.17 KB
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
from flask import Flask
from time import sleep
from ev3dev.auto import Sound
from robot.robot import PyraminxRobot
from const import *
app = Flask(__name__)
robot = PyraminxRobot()
@app.route('/ping')
def ping():
return 'pong'
@app.route('/execute/<args>')
def execute(args):
try:
cmd = args.split(':')
robot.soft_reset()
tips = '' if len(cmd) < 2 else cmd[1]
robot.execute(cmd[0], tips)
robot.cart.cart_drv(CART_POS_C)
sleep(1)
robot.relax()
except Exception as e:
return 'error: ' + str(e)
return 'ok'
@app.route('/flip/<cmd>')
def flip(cmd):
try:
robot.soft_reset()
robot.flip(cmd)
robot.cart.cart_drv(CART_POS_C)
sleep(1)
robot.relax()
except Exception as e:
return 'error: ' + str(e)
return 'ok'
@app.route('/reset')
def reset():
try:
robot.reset()
Sound.speak('Reset complete').wait()
sleep(1)
robot.relax()
except Exception as e:
return 'error: ' + str(e)
return 'ok'
if __name__ == '__main__':
Sound.speak('Pyraminx').wait()
app.run(host='0.0.0.0', debug=True, use_reloader=False)