-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRWS4YuMi.py
148 lines (125 loc) · 4.24 KB
/
RWS4YuMi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/python3
# -*- coding: utf-8 -*-
'''
| author:
| Belal HMEDAN, LIG lab/ Marvin Team, France, 2021.
| RWS4YuMi API.
'''
from requests import get
from requests.auth import HTTPDigestAuth
import xml.etree.ElementTree as ET
from time import sleep
#======================
# class actionHandler |
#======================
class RWS4YuMi():
def __init__(self, host='192.168.125.1:80', username='Default User', password='robotics'):
"""
Class RWS4YuMi: API with ABB YuMI IRB14000 Robot.
---
Parameters:
@param: host, string, root ip address and port 80 for http.
@param: username, string, username.
@param: password, string, password.
"""
self.host = host
self.username = username
self.password = password
def actionStatus(self):
"""
Function: actionStatus, to get the robot status: running/stopped.
---
Parameters:
@param: None
---
@return: status, string, running/stopped.
"""
url = "http://"+self.host+"/rw/rapid/execution"
status = ''
r = get(url, auth=HTTPDigestAuth(self.username, self.password), verify=False, stream=True)
if(r.status_code != 200):
print("Exit with Request Error Code: ", r.status_code)
return None
tree = ET.fromstring(r.content)
k = {'class': 'ctrlexecstate'}
for child in tree[1].iter('*'):
if child.attrib==k:
status = child.text
return status
def getRobtarget(self, mechUnit='ROB_L'):
"""
Function: getRobtarget, to get the robot robtarget.
---
Parameters:
@param: mechUnit, string, 'ROB_L' or 'ROB_R'.
---
@return: robtarget, list of lists, robtarget.
"""
url = "http://"+self.host+"/rw/motionsystem/mechunits/"+mechUnit+"/robtarget"
r = get(url, auth=HTTPDigestAuth(self.username, self.password), verify=False, stream=True)
if(r.status_code != 200):
print("Exit with Request Error Code: ", r.status_code)
return False
tree = ET.fromstring(r.content)
for child in tree[1].iter('*'):
if child.attrib == {'class': 'x'}:
x = float(child.text)
elif child.attrib == {'class': 'y'}:
y = float(child.text)
elif child.attrib == {'class': 'z'}:
z = float(child.text)
elif child.attrib == {'class': 'q1'}:
q1 = float(child.text)
elif child.attrib == {'class': 'q2'}:
q2 = float(child.text)
elif child.attrib == {'class': 'q3'}:
q3 = float(child.text)
elif child.attrib == {'class': 'q4'}:
q4 = float(child.text)
elif child.attrib == {'class': 'cf1'}:
cf11 = float(child.text)
elif child.attrib == {'class': 'cf4'}:
cf14 = float(child.text)
elif child.attrib == {'class': 'cf6'}:
cf16 = float(child.text)
elif child.attrib == {'class': 'cfx'}:
cf1x = float(child.text)
elif child.attrib == {'class': 'eax_a'}:
eax_a = float(child.text)
robtarget = [[x, y, z], [q1, q2, q3, q4], [cf11, cf14, cf16, cf1x], [eax_a, '9E+09', '9E+09', '9E+09', '9E+09', '9E+09']] # eax_b, eax_c, eax_d, eax_e, eax_f]]
return robtarget
def getJointtarget(self, mechUnit='ROB_L'):
"""
Function: getJointtarget, to get the robot robtarget.
---
Parameters:
@param: mechUnit, string, 'ROB_L' or 'ROB_R'.
---
@return: jointtarget, list of lists, jointtarget.
"""
url = "http://"+self.host+"/rw/motionsystem/mechunits/"+mechUnit+"/jointtarget"
r = get(url, auth=HTTPDigestAuth(self.username, self.password), verify=False, stream=True)
if(r.status_code != 200):
print("Exit with Request Error Code: ", r.status_code)
return False
tree = ET.fromstring(r.content)
for child in tree[1].iter('*'):
if child.attrib == {'class': 'rax_1'}:
rax_1 = float(child.text)
elif child.attrib == {'class': 'rax_2'}:
rax_2 = float(child.text)
elif child.attrib == {'class': 'rax_3'}:
rax_3 = float(child.text)
elif child.attrib == {'class': 'rax_4'}:
rax_4 = float(child.text)
elif child.attrib == {'class': 'rax_5'}:
rax_5 = float(child.text)
elif child.attrib == {'class': 'rax_6'}:
rax_6 = float(child.text)
elif child.attrib == {'class': 'eax_a'}:
eax_a = float(child.text)
jointtarget = [[rax_1, rax_2, rax_3, rax_4, rax_5, rax_6], [eax_a, '9E+09', '9E+09', '9E+09', '9E+09', '9E+09']] # eax_b, eax_c, eax_d, eax_e, eax_f]]
return jointtarget
#-------------------------------------------------------------
# api = RWS4YuMi()
# print(api.getRobtarget())