51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
# simulation of a robot
|
|
|
|
from flask import Flask, request, jsonify
|
|
import requests
|
|
import time
|
|
|
|
robot_control_server_url = 'http://localhost:50055/v1'
|
|
|
|
class RexRobot:
|
|
def __init__(self):
|
|
self.id = "B29"
|
|
self.firmwareVersion = "0.0.1"
|
|
self.currentJobId = ""
|
|
|
|
# connecting with robot server
|
|
print("connecting with robot server")
|
|
|
|
res = requests.api.post(robot_control_server_url + "/robot",
|
|
json={'id': self.id, 'type': 1, 'firmwareVersion': self.firmwareVersion})
|
|
|
|
if res.status_code == 403:
|
|
print("permit join disabled")
|
|
exit(1) # esp should here restart
|
|
|
|
def setCurrentJobId(self, jobId):
|
|
self.currentJobId = jobId
|
|
|
|
rex = RexRobot()
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/api/v1/control', methods=['POST'])
|
|
def hello():
|
|
body = request.get_json()
|
|
|
|
print("controlling robot", body)
|
|
|
|
time.sleep(15)
|
|
|
|
|
|
print("robot controlled")
|
|
|
|
return jsonify({'status': 'ok'})
|
|
|
|
@app.route('/api/v1/ping', methods=['GET'])
|
|
def ping():
|
|
print("pong")
|
|
return jsonify({'status': 'ok'})
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=False, port=5000) |