updated roboter lib
parent
7a15a9379c
commit
772b738aab
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"category": "RexRobots",
|
"category": "RexRobots",
|
||||||
"name": "Produktionstask 1",
|
"name": "Rex test - Drucker leeren",
|
||||||
"globalInputs": [],
|
"globalInputs": [],
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"name": "Bild zu Label konvertieren",
|
"name": "Ausführen",
|
||||||
"onFinish": "next",
|
"onFinish": "next",
|
||||||
"undoPossible": false,
|
"undoPossible": false,
|
||||||
"repeatPossible": true,
|
"repeatPossible": true,
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import random
|
|
||||||
import time
|
|
||||||
|
|
||||||
# add the path to the libs folder
|
# add the path to the libs folder
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
||||||
|
|
||||||
from libs.robots import rex
|
from libs.robots import rex
|
||||||
|
'''
|
||||||
randomJobs = [
|
randomJobs = [
|
||||||
"Drucker leeren",
|
"Drucker leeren",
|
||||||
"Müll rausbringen",
|
"Müll rausbringen",
|
||||||
|
@ -23,19 +21,14 @@ randomJobs = [
|
||||||
|
|
||||||
rJob = randomJobs[random.randint(0, len(randomJobs) - 1)]
|
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")
|
print("no finish")
|
||||||
rexRobot.finish()
|
rexRobot.finish()
|
Binary file not shown.
|
@ -1,6 +1,5 @@
|
||||||
import requests
|
import requests
|
||||||
import uuid
|
import uuid
|
||||||
from enum import Enum
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -14,6 +13,9 @@ class ResponseStatus():
|
||||||
|
|
||||||
max_job_name_length = 30
|
max_job_name_length = 30
|
||||||
|
|
||||||
|
class ToolHead():
|
||||||
|
Gripper = 0
|
||||||
|
|
||||||
###
|
###
|
||||||
# CLASSES
|
# CLASSES
|
||||||
###
|
###
|
||||||
|
@ -25,18 +27,22 @@ class Rex:
|
||||||
"""
|
"""
|
||||||
This class represents a rex robot.
|
This class represents a rex robot.
|
||||||
"""
|
"""
|
||||||
def __init__(self, robotName, jobName, address='http://localhost:50055'):
|
def __init__(self, robot_name, job_name, address='http://localhost:50055'):
|
||||||
self.robotName = robotName
|
self.robot_name = robot_name
|
||||||
self.jobId = uuid.uuid4().__str__()
|
self.job_id = uuid.uuid4().__str__()
|
||||||
self.jobName = jobName[:max_job_name_length]
|
self.job_name = job_name[:max_job_name_length]
|
||||||
self.address = address
|
self.address = address
|
||||||
self.x = 0
|
self.x = 0
|
||||||
self.y = 0
|
self.y = 0
|
||||||
self.z = 0
|
self.z = 0
|
||||||
self.connectedModule = 0
|
self.tool_head = 0
|
||||||
|
|
||||||
def _request_data(self):
|
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):
|
def _post_request(self, json):
|
||||||
obj = {}
|
obj = {}
|
||||||
|
@ -46,8 +52,9 @@ class Rex:
|
||||||
|
|
||||||
res = requests.post(self.address + '/v1/control/1', json=obj)
|
res = requests.post(self.address + '/v1/control/1', json=obj)
|
||||||
|
|
||||||
print("status code", res.status_code)
|
if res.status_code != 200:
|
||||||
print("res", res.json())
|
print("status code", res.status_code)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
json = res.json()
|
json = res.json()
|
||||||
|
|
||||||
|
@ -65,43 +72,44 @@ class Rex:
|
||||||
print("robot some other error")
|
print("robot some other error")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def move_to_x(self, x):
|
def move_to(self, x = None, y = None, z = None, AprilTagId = None):
|
||||||
"""
|
|
||||||
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.
|
Move the robot to the new position.
|
||||||
"""
|
"""
|
||||||
self.x = x
|
data = {}
|
||||||
self.y = y
|
|
||||||
self.z = z
|
|
||||||
|
|
||||||
print('Robot: ' + self.robotName + ' moved to (' + str(self.x) + ', ' + str(self.y) + ')')
|
if x != None:
|
||||||
|
self.x = x
|
||||||
self._post_request({'x': self.x, 'y': self.y, 'z': self.z})
|
data['x'] = self.x
|
||||||
|
|
||||||
def change_connected_module(self, module):
|
if y != None:
|
||||||
|
self.y = y
|
||||||
|
data['y'] = self.y
|
||||||
|
|
||||||
|
if z != None:
|
||||||
|
self.z = z
|
||||||
|
data['z'] = self.z
|
||||||
|
|
||||||
|
if len(data) == 0:
|
||||||
|
print("No data provided for move_to")
|
||||||
|
return
|
||||||
|
|
||||||
|
if AprilTagId != None:
|
||||||
|
data['AprilTagId'] = AprilTagId
|
||||||
|
|
||||||
|
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):
|
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
|
# 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)
|
print("status code", res.status_code)
|
Loading…
Reference in New Issue