updated roboter lib

main
alex 2023-10-25 22:06:35 +02:00
parent 7a15a9379c
commit 772b738aab
4 changed files with 59 additions and 55 deletions

View File

@ -1,10 +1,10 @@
{
"category": "RexRobots",
"name": "Produktionstask 1",
"name": "Rex test - Drucker leeren",
"globalInputs": [],
"tasks": [
{
"name": "Bild zu Label konvertieren",
"name": "Ausführen",
"onFinish": "next",
"undoPossible": false,
"repeatPossible": true,

View File

@ -1,13 +1,11 @@
import sys
import os
import random
import time
# add the path to the libs folder
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from libs.robots import rex
'''
randomJobs = [
"Drucker leeren",
"Müll rausbringen",
@ -23,19 +21,14 @@ randomJobs = [
rJob = randomJobs[random.randint(0, len(randomJobs) - 1)]
print("job: " + rJob)
print("job: " + rJob)'''
rexRobot = rex.Rex("test", rJob)
rexRobot = rex.Rex("test", "Drucker leeren")
# rexRobot.moveToXYZ(1, 2, 3)
rexRobot.move_to(x=15, z=20, AprilTagId=1)
rexRobot.change_tool_head(rex.ToolHead.Gripper)
rexRobot.move_to(y=5)
rexRobot.move_to_x(5)
time.sleep(5)
rexRobot.move_to_x(5)
time.sleep(5)
print("no finish")
rexRobot.finish()

View File

@ -1,6 +1,5 @@
import requests
import uuid
from enum import Enum
import sys
###
@ -14,6 +13,9 @@ class ResponseStatus():
max_job_name_length = 30
class ToolHead():
Gripper = 0
###
# CLASSES
###
@ -25,18 +27,22 @@ class Rex:
"""
This class represents a rex robot.
"""
def __init__(self, robotName, jobName, address='http://localhost:50055'):
self.robotName = robotName
self.jobId = uuid.uuid4().__str__()
self.jobName = jobName[:max_job_name_length]
def __init__(self, robot_name, job_name, address='http://localhost:50055'):
self.robot_name = robot_name
self.job_id = uuid.uuid4().__str__()
self.job_name = job_name[:max_job_name_length]
self.address = address
self.x = 0
self.y = 0
self.z = 0
self.connectedModule = 0
self.tool_head = 0
def _request_data(self):
return {'robotName': self.robotName, 'jobId': self.jobId, 'jobName': self.jobName}
return {
'robotName': self.robot_name,
'jobId': self.job_id,
'jobName': self.job_name
}
def _post_request(self, json):
obj = {}
@ -46,8 +52,9 @@ class Rex:
res = requests.post(self.address + '/v1/control/1', json=obj)
if res.status_code != 200:
print("status code", res.status_code)
print("res", res.json())
sys.exit(1)
json = res.json()
@ -65,43 +72,44 @@ class Rex:
print("robot some other error")
sys.exit(1)
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):
def move_to(self, x = None, y = None, z = None, AprilTagId = None):
"""
Move the robot to the new position.
"""
data = {}
if x != None:
self.x = x
data['x'] = self.x
if y != None:
self.y = y
data['y'] = self.y
if z != None:
self.z = z
data['z'] = self.z
print('Robot: ' + self.robotName + ' moved to (' + str(self.x) + ', ' + str(self.y) + ')')
if len(data) == 0:
print("No data provided for move_to")
return
self._post_request({'x': self.x, 'y': self.y, 'z': self.z})
if AprilTagId != None:
data['AprilTagId'] = AprilTagId
def change_connected_module(self, module):
print('Robot: ' + self.robot_name + ' moved to ' + str(data))
self._post_request(data)
def change_tool_head(self, tool_head = int):
"""
Change the connected module.
Change the tool head.
"""
print('Robot: ' + self.robotName + ' changed connected module to ' + str(module))
print('Robot: ' + self.robot_name + ' changed tool head to ' + str(tool_head))
data = {'ToolHead': tool_head}
self._post_request(data)
def finish(self):
"""
@ -112,6 +120,9 @@ class Rex:
# TODO: request to the server to finish the robot and update the robot status to idle
res = requests.post(self.address + '/v1/control/1/finish', json={'robotName': self.robotName, 'jobId': self.jobId})
res = requests.post(self.address + '/v1/control/1/finish', json={
'robotName': self.robot_name,
'jobId': self.job_id
})
print("status code", res.status_code)