-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
86 lines (64 loc) · 1.5 KB
/
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
import time
from bottle import request, route, run, static_file
import doomba as doomba_
import vulcanuino
class MockObject(object):
def __getattr__(self, name):
print name
return lambda *args, **kwargs: None
try:
doomba = doomba_.Doomba()
except:
print "Warning: Roomba not connected"
doomba = MockObject()
try:
gun = vulcanuino.Vulcanuino()
except:
print "Warning: Gun not connected"
gun = MockObject()
@route('/')
def home():
return static_file('controls.html', root='/Users/nat/code/doomba/control_page')
@route('/reset')
def reset_doomba():
global doomba
doomba = doomba_.Doomba()
@route('/forward')
def go_forward():
doomba.forward()
@route('/back')
def go_back():
doomba.back()
@route('/speed')
def set_speed():
doomba.speed = int(request.query.speed) or 100
@route('/forward_left')
def go_forward_left():
doomba.forward_left()
@route('/forward_right')
def go_forward_right():
doomba.forward_right()
@route('/left')
def turn_left():
doomba.left()
@route('/right')
def turn_right():
doomba.right()
@route('/custom')
def custom_movement():
left = request.query.left or 0
right = request.query.right or 0
doomba.drive_direct(left, right)
@route('/stop')
def stop_moving():
doomba.stop()
@route('/fire')
def shoot_dart():
gun.single_shot()
@route('/start_rampage')
def start_rampage():
gun.commence_firing()
@route('/end_rampage')
def end_rampage():
gun.cease_fire()
run(host='10.12.5.29', port=8080)