-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (50 loc) · 1.97 KB
/
app.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
from tornado import websocket, web, ioloop
import json
import logging
import breezy_robot_handler
logging.basicConfig(level=logging.DEBUG)
c = []
rhandle = breezy_robot_handler.RobotHandler()
class IndexHandler(web.RequestHandler):
def get(self):
self.render('BotControl.html')
class EchoWebSocket(websocket.WebSocketHandler):
def open(self):
logging.debug('WebSocket opened')
def on_message(self, message):
if message == 'init':
return
c = message.split(',')
x = int(float(c[1])) * -1 # Negate linear velocity
y = int(float(c[0]))
#logging.debug(message)
self.write_message(u'linear V: ' + str(x) + ' angular V: ' + str(y))
try:
rhandle.go(x, y)
except:
pass
def on_close(self):
logging.debug('WebSocket closed')
app = web.Application([
(r'/', IndexHandler),
(r'/ws', EchoWebSocket),
#(r'/api', ApiHandler),
(r'/(config.js)', web.StaticFileHandler, {'path': './'}),
(r'/(BotControl.css)', web.StaticFileHandler, {'path': './'}),
(r'/(adapter.js)', web.StaticFileHandler, {'path': './'}),
(r'/(jquery-1.10.2.js)', web.StaticFileHandler, {'path': './'}),
(r'/(jquery.signalR-2.2.0.js)', web.StaticFileHandler, {'path': './'}),
(r'/(Vector2.js)', web.StaticFileHandler, {'path': './'}),
(r'/(victor.min.js)', web.StaticFileHandler, {'path': './'}),
(r'/(VectorFacade.js)', web.StaticFileHandler, {'path': './'}),
(r'/(connectionManager.js)', web.StaticFileHandler, {'path': './'}),
(r'/(viewModel.js)', web.StaticFileHandler, {'path': './'}),
(r'/(app.js)', web.StaticFileHandler, {'path': './'}),
(r'/(BotControl.js)', web.StaticFileHandler, {'path': './'}),
(r'/(rx.all.min.js)', web.StaticFileHandler, {'path': './'}),
(r'/(rx.all.map)', web.StaticFileHandler, {'path': './'})
])
if __name__ == '__main__':
rhandle.init_bot('trash')
app.listen(8888)
ioloop.IOLoop.instance().start()