admin-dashboard-backend/groupTasks/libs/robots/rex.py

76 lines
1.9 KiB
Python

import requests
import uuid
class Rex:
"""
This class represents a rex robot.
"""
def __init__(self, rexName, jobName):
self.rexName = rexName
self.jobId = uuid.uuid4().__str__()
self.jobName = jobName
self.x = 0
self.y = 0
self.z = 0
self.connectedModule = 0
def _request_data(self):
return {'robotName': self.rexName, 'jobid': self.jobId, 'jobName': self.jobName}
def _post_request(self, json):
obj = {}
obj = self._request_data()
obj['task'] = json
res = requests.post('http://localhost:50055/v1/control/0', json=obj)
def move_to_x(self, x):
"""
Move the robot to the new x position.
"""
self.x = x
self._post_request({'x': self.x})
def move_to_y(self, y):
"""
Move the robot to the new y position.
"""
self.y = y
def move_to_z(self, z):
"""
Move the robot to the new z position.
"""
self.z = z
def move_to_xyz(self, x, y, z):
"""
Move the robot to the new position.
"""
self.x = x
self.y = y
self.z = z
print('Robot: ' + self.rexName + ' moved to (' + str(self.x) + ', ' + str(self.y) + ')')
# requests.post('http://localhost:50055/v1/control/move', json={'x': self.x, 'y': self.y, 'z': self.z})
self._post_request({'x': self.x, 'y': self.y, 'z': self.z})
def change_connected_module(self, module):
"""
Change the connected module.
"""
print('Robot: ' + self.rexName + ' changed connected module to ' + str(module))
def finish():
"""
Finish the robot.
This will update the robot status to free.
"""
print('Robot finished')
# TODO: request to the server to finish the robot and update the robot status to free