-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp2.py
90 lines (63 loc) · 2.36 KB
/
app2.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
import logging
import time
import json
from threading import Timer, Thread
from requests import Session
from signalr import Connection
import breezy_robot_handler
logging.basicConfig(level=logging.DEBUG)
RHANDLER = breezy_robot_handler.RobotHandler()
def signal_r_setup():
with Session() as session:
# create a connection
#connection = Connection("https://atbot01.azurewebsites.net/signalr", session)
connection = Connection("https://dube.azurewebsites.net/signalr", session)
#connection = Connection("http://localhost:6658/signalr", session)
# get control hub
bot = connection.register_hub('BotControl')
hub = connection.register_hub('WebRtcHub')
# start a connection
connection.start()
t = Timer(.1, RHANDLER.stop)
hub.server.invoke('registerBot', 'PyBot')
print('connected to SignalR hub... connection id: ' + connection.token)
# create new control message handler
def handle_bot_control_request(data):
print('received: ', data)
try:
command = data['Command']
#RHANDLER.get_sensors()
if command == "turn":
RHANDLER.turn(data)
elif command == "rise":
RHANDLER.rise(data)
else:
#RHANDLER.go(data)
RHANDLER.go_direct(data)
t.cancel()
t = Timer(0.50, RHANDLER.stop)
t.start()
except:
pass
def send_telemetry():
cnt = 0
while True:
cnt = cnt + 1
j = RHANDLER.get_sensors()
bot.server.invoke('sendBotTelemetry', j)
time.sleep(5)
# receive new chat messages from the hub
bot.client.on('controllerAt', handle_bot_control_request)
thread = Thread(target=send_telemetry, args=())
thread.daemon = True
thread.start()
# create error handler
def print_error(error):
print('error: ', error)
# process errors
connection.error += print_error
# wait before exit
connection.wait(None)
if __name__ == '__main__':
RHANDLER.init_bot()
signal_r_setup()