-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleop_server.py
executable file
·100 lines (79 loc) · 2.14 KB
/
teleop_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright (c) 2014,2020 ADLINK Technology Inc.
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Author: Gabriele Baldoni
import os
import sys
import json
from flask import Flask
from flask_cors import CORS, cross_origin
from yaks import Yaks, Value, Encoding
CONTROL_RESOURCE = '/turtlebot/move'
STATE_RESOURCE = '/turtlebot/status'
SENSOR_RESOURCE = '/turtlebot/sensors'
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
def response():
res = ws.get(STATE_RESOURCE)
print(res)
if len(res) > 0:
v = res[0].get_value().get_value()
return v
return ""
@app.route('/', methods=['GET'])
@cross_origin()
def index():
return response()
@app.route('/sensors', methods=['GET'])
@cross_origin()
def sensors():
return response()
@app.route('/fwd', methods=['POST'])
@cross_origin()
def fwd():
v = Value('fwd', Encoding.STRING)
ws.put(CONTROL_RESOURCE, v)
return response()
@app.route('/bwd', methods=['POST'])
@cross_origin()
def bwd():
v = Value('bwd', Encoding.STRING)
ws.put(CONTROL_RESOURCE, v)
return response()
@app.route('/stop', methods=['POST'])
@cross_origin()
def stop():
v = Value('h', Encoding.STRING)
ws.put(CONTROL_RESOURCE, v)
return response()
@app.route('/sx', methods=['POST'])
@cross_origin()
def sx():
v = Value('sx', Encoding.STRING)
ws.put(CONTROL_RESOURCE, v)
return response()
@app.route('/dx', methods=['POST'])
@cross_origin()
def dx():
v = Value('dx', Encoding.STRING)
ws.put(CONTROL_RESOURCE, v)
return response()
def main():
yip = sys.argv[1]
global yaks
yaks = Yaks.login(yip)
global ws
ws = yaks.workspace('/')
app.run(debug=True,host='0.0.0.0')
if __name__ == '__main__':
main()