67 lines
1.4 KiB
Python
67 lines
1.4 KiB
Python
# simulation of a robot
|
|
|
|
from flask import Flask, request, jsonify
|
|
import requests
|
|
import time
|
|
import random
|
|
|
|
robot_control_server_url = 'http://localhost:50055/v1'
|
|
|
|
class RexRobot:
|
|
def __init__(self, id):
|
|
self.id = id
|
|
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
|
|
|
|
# generate random id
|
|
def randomId():
|
|
return random.randint(0, 100)
|
|
|
|
# 10 random rexrobot
|
|
|
|
RexRobot("test")
|
|
#RexRobot("759")
|
|
'''
|
|
for i in range(1):
|
|
#RexRobot(str(randomId()))
|
|
RexRobot("759")
|
|
RexRobot("760")
|
|
RexRobot("761")
|
|
RexRobot("762")
|
|
RexRobot("763")
|
|
RexRobot("764")
|
|
RexRobot("770")'''
|
|
|
|
#rex = RexRobot("k5")
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/api/v1/control', methods=['POST'])
|
|
def hello():
|
|
body = request.get_json()
|
|
|
|
print("controlling robot", body)
|
|
|
|
time.sleep(1)
|
|
|
|
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) |