-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCollect.py
More file actions
215 lines (183 loc) · 7.55 KB
/
DataCollect.py
File metadata and controls
215 lines (183 loc) · 7.55 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# -*- coding: UTF-8 -*-
import logging
logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# import for LeapMotion
import Leap, sys, thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture, Vector
# import for UR3
import urx
import math
from math import pi
# create thread to execute the two UR3 simualtanious
import threading
from threading import Thread
import time
class printer:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
@classmethod
def okb(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.OKBLUE + t + ' ' + text + cls.ENDC)
@classmethod
def okg(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.OKGREEN + t + ' ' + text + cls.ENDC)
@classmethod
def warn(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.WARNING + t + ' ' + text + cls.ENDC)
@classmethod
def header(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.HEADER + t + ' ' + text + cls.ENDC)
@classmethod
def fail(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.FAIL + t + ' ' + text + cls.ENDC)
@classmethod
def bold(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.BOLD + t + ' ' + text + cls.ENDC)
@classmethod
def underline(cls, text):
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(cls.UNDERLINE + t + ' ' + text + cls.ENDC)
class UR3:
Left_UR3_IP = "158.132.172.193"
Right_UR3_IP = "158.132.172.214"
@classmethod
def connectLeftUR(cls):
rob = urx.Robot(cls.Left_UR3_IP)
rob.set_tcp((0,0,0,0,0,0))
rob.set_payload(1.5, (0,0,0))
time.sleep(0.2)
printer.header("==================== Left UR3 connected. ====================")
intial_joints = [-0.03303844133485967, -0.4258616606341761, 1.2580962181091309, -3.8896873633014124, -1.6458943525897425, 9.371907297764913]
# [-0.027399841939107716, -0.9967621008502405, 1.7950401306152344, -3.9452269713031214, -1.5623214880572718, 9.370444122944967]
rob.movej(intial_joints, acc= 0.3, vel=0.2)
printer.header("==================== Left UR3 finished initial setting. ====================")
return rob
@classmethod
def moveLeftPose(cls, rob, pos_displace, angle = 0.0):
try:
l = 0.02
v = 0.10 # velocity
a = 0.20 # acceleration
pose = rob.getl()
t = rob.get_pose()
# t0 = rob.get_pose()
print("Left UR: the current pose is : %s" % t.pos)
# print("Translate in -x and rotate")
# t0.orient.rotate_zb(pi/18)
for i in range(3):
if i == 0: # in / out
t.pos[i] += pos_displace[i]/3.0
elif i == 1: # up / down
t.pos[i] += pos_displace[i]/1.5
else: # left / right
t.pos[i] += pos_displace[i]/2.0
print("Left UR: the target pose is %s with a displacement %s" % (t.pos, pos_displace))
# pose=list(t.pos)
# rob.movel(pose, vel=v, acc=a)
angle_rad = angle/180 * pi
t.orient.rotate_zt(angle_rad)
rob.set_pose(t, vel=v, acc=a)
print("Left UR: the changed pose is : %s" % rob.getl())
printer.okg("Left UR: ************** Left UR Moved Successfully! ***************")
# time.sleep(0.005)
# time.sleep(0.0001)
# forward pos[0] +
# backward pos[0] -
# up pos[1] -
# down pos[1] +
# left pos[2] +
# right pos[2] -
# move out
# rob.set_pose(t0, vel=v, acc=a)
finally:
pass
# rob.close()
# print("The UR3 robot is disconnected")
@classmethod
def moveRightPose(cls, rob, pos_displace):
try:
l = 0.02
v = 0.1 # velocity
a = 0.2 # acceleration
pose = rob.getl()
t = rob.get_pose() # transformation from Base to TCP
# t0 = rob.get_pose()
print("Right UR: the current pose is : %s" % pose)
# print("Translate in -x and rotate")
# t0.orient.rotate_zb(pi/18)
for i in range(3):
if i == 0: # in / out
pose[i] += pos_displace[i]/3.0
elif i == 1: # up / down
pose[i] += pos_displace[i]/1.5
else: # left / right
pose[i] += pos_displace[i]/2.0
print("Right UR: the target pose is %s with a displacement %s" % (pose, pos_displace))
rob.movel(pose, vel=v, acc=a)
print("Right UR: the current pose is : %s" % rob.getl())
printer.okg("Right UR: ************** Right UR Moved Successfully! ***************")
time.sleep(0.0001)
# forward pos[0] +
# backward pos[0] -
# up pos[1] -
# down pos[1] +
# left pos[2] +
# right pos[2] -
# move out
# rob.set_pose(t0, vel=v, acc=a)
finally:
rob.close()
# print("The UR3 robot is disconnected")
if __name__ == "__main__":
leftrob = UR3.connectLeftUR()
try:
if leftrob.is_program_running():
pass
else:
printer.okg("Left UR starts to run!")
# lh_displace = [3.06105, -1.69905, -3.02684]
#----------------------------
lh_displace = [60, 0, 0]
# left - right +
final_angle = 60.0
left_pos_displace = [-lh_displace[2]/500.0, -lh_displace[1]/500.0, -lh_displace[0]/500.0]
UR3.moveLeftPose(leftrob, left_pos_displace, final_angle)
#----------------------------
time.sleep(6)
#----------------------------
time.sleep(6)
#----------------------------
lh_displace = [30, 0, 0]
left_pos_displace = [-lh_displace[2]/500.0, -lh_displace[1]/500.0, -lh_displace[0]/500.0]
final_angle = -120.0
UR3.moveLeftPose(leftrob, left_pos_displace, final_angle)
#----------------------------
lh_displace = [-30, 0, 0]
left_pos_displace = [-lh_displace[2]/500.0, -lh_displace[1]/500.0, -lh_displace[0]/500.0]
final_angle = 120.0
UR3.moveLeftPose(leftrob, left_pos_displace, final_angle)
#----------------------------
lh_displace = [180, -80, -240]
left_pos_displace = [-lh_displace[2]/500.0, -lh_displace[1]/500.0, -lh_displace[0]/500.0]
final_angle = 70.0
UR3.moveLeftPose(leftrob, left_pos_displace, final_angle)
#----------------------------
intial_joints = [-0.03303844133485967, -0.4258616606341761, 1.2580962181091309, -3.8896873633014124, -1.6458943525897425, 9.371907297764913]
leftrob.movej(intial_joints, acc= 0.3, vel=0.2)
# UR3.moveLeftPose(leftrob, left_pos_displace, final_angle)
# time.sleep(3)
finally:
leftrob.close()